62,074
社区成员
发帖
与我相关
我的任务
分享
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Register(string textUserCode, string textPassword, string textPasswordConfirm, string textName, string textBirthday, string textArea,
string textJob, string textPhone, string textEmail, string textMemo)
{
Business.User user = new User();
if (string.IsNullOrEmpty(textUserCode))
{
ModelState.AddModelError("textUserCode", "请输入用户名!");
}
else
{
if (Encoding.Default.GetByteCount(textUserCode) > 50)
{
ModelState.AddModelError("textUserCode", "长度不能超过50!");
}
else
{
bool result = user.IsUserExist(textUserCode);
if (result)
{
ModelState.AddModelError("textUserCode", "用户名已存在!");
}
}
}
if (textPassword.Length < 6 || textPassword.Length > 10)
{
ModelState.AddModelError("textPassword", "密码必须在6-10位之间!");
}
else
{
if (textPassword != textPasswordConfirm)
ModelState.AddModelError("textPasswordConfirm", "两次密码输入不一致!");
}
//个人资料栏的验证
if (Encoding.Default.GetByteCount(textName) > 50)
{
ModelState.AddModelError("textName", "长度不能超过50!");
}
if (Encoding.Default.GetByteCount(textArea) > 50)
{
ModelState.AddModelError("textArea", "长度不能超过50!");
}
if (Encoding.Default.GetByteCount(textJob) > 50)
{
ModelState.AddModelError("textJob", "长度不能超过50!");
}
if (Encoding.Default.GetByteCount(textEmail) > 50)
{
ModelState.AddModelError("textEmail", "长度不能超过50!");
}
if (Encoding.Default.GetByteCount(textMemo) > 50)
{
ModelState.AddModelError("textMemo", "长度不能超过200!");
}
if (!ModelState.IsValid)
return View();
//ModelState.AddModelError("textUserCode", "用户名已存在!");
//ModelState.AddModelError("textPassword", "密码必须在6-10位之间!");
Hashtable htUser = new Hashtable();
htUser["USER_CODE"] = textUserCode;
htUser["USER_PWD"] = SecurityUtil.Encrypt(textPassword, textUserCode);
htUser["USER_NAME"] = textName;
htUser["USER_MOTHER_LAND"] = textArea;
htUser["USER_WORK"] = textJob;
if (!string.IsNullOrEmpty(textBirthday.TrimStart().TrimEnd()))
htUser["USER_BIRTHDAY"] = textBirthday;
htUser["USER_PHONE"] = textPhone;
htUser["USER_EMAIL"] = textEmail;
htUser["USER_MEMO"] = textMemo;
htUser["UPDATE_DATE"] = htUser["CREATE_DATE"] = DateTime.Now;
if (user.InsertUser(htUser))
{
//Response.Write("<javascript>alert('注册成功!');</javascript>");
return RedirectToAction("Login");//这里可以跳转成功
}
else
return View();
}
$(document).ready(function() {
$("#imgCheckCode").attr("src", "GetCheckPage.aspx?tempid=" + new Date().getTime()); //显示验证码
$("#chckPassword").check();
var m = $.Max(2, 3);
//提交
$("#buttonLogin").click(function() {
$.ajax({
data: { "userName": $("#textUser").val(), "password": $("#textPassword").val(), "checkCode": $("#textCheckCode").val() },
dataType: "json",
url: "CheckLogin.aspx",--这里是登录验证的请求url
success: function(data, textStatus) {
if (data == -1) {
alert("验证码输入有误!");
}
else if (data == 0) {
alert("用户名不存在或密码错误!");
}
else if (data == 1) {
window.location = "Home.aspx";
}
}
});
});
$("#buttonRegister").click(function() {
window.location = "Register.aspx";
});
});
public ActionResult CheckLogin()
{
//result -1:验证码错误 0:用户密码验证失败 1:成功
int result = (Request.Params["checkCode"].ToString() == GlobalVariable.GlobalSession["CheckCode"].ToString()) ? 0 : -1;
if (result == -1)
return new JsonResult { Data = result };
Business.User user = new User();
result = user.CheckUser(Request.Params["userName"].ToString(), Request.Params["password"].ToString()) ? 1 : 0;
if (result == 1)
{
Session["IsLogin"] = 1;
return new JsonResult { Data = result };
}
return Redirect("/Home/HomePage");//我想在这里跳转到HomeController下的HomePage这个Action执行返回后的View。但是方法执行到了,就是url没有跳转。
//return RedirectToRoute("HomePage");
//return RedirectToAction("HomePage", "Home");
}
public ActionResult HomePage()
{
return View("Home");
}