Example #1
0
 public ActionResult ChangeInfo(User user)
 {
     userRsy = new UserRepository();
     if(userRsy.Authentication(UserName,Ninesky.Common.Text.Sha256(user.Password))==0)
     {
         var _user = userRsy.Find(UserName);
         _user.Gender = user.Gender;
         _user.Email = user.Email;
         _user.QQ = user.QQ;
         _user.Tel = user.Tel;
         _user.Address = user.Address;
         _user.PostCode = user.PostCode;
         if (userRsy.Update(_user))
         {
             Notice _n = new Notice { Title = "修改资料成功", Details = "您已经成功修改资料!", DwellTime = 5, NavigationName = "用户首页", NavigationUrl = Url.Action("Default", "User") };
             return RedirectToAction("UserNotice", "Prompt", _n);
         }
         else
         {
             Error _e = new Error { Title = "修改资料失败", Details = "在修改用户资料时时,更新的资料未能保存到数据库", Cause = "系统错误", Solution = Server.UrlEncode("<li>返回<a href='" + Url.Action("ChangeInfo", "User") + "'>修改资料</a>页面,输入正确的信息后重新操作</li><li>联系网站管理员</li>") };
             return RedirectToAction("UserError", "Prompt", _e);
         }
     }
     else
     {
         ModelState.AddModelError("Password","密码错误!");
         return View();
     }
 }
Example #2
0
 public ActionResult Register(RegisterViewModel register)
 {
     InterfaceUserService userService = new UserService();
     if (TempData["VerficationCode"] == null || TempData["VerficationCode"].ToString() != register.VerificationCode.ToUpper())
     {
         ModelState.AddModelError("VerficationCode", "验证码不正确");
         return View(register);
     }
     if (ModelState.IsValid)
     {
         if (userService.Exist(register.UserName)) ModelState.AddModelError("UserName", "用户名已存在");
         else
         {
             User _user = new User()
             {
                 UserName = register.UserName,
                 //默认用户组代码写这里
                 DisplayName = register.DisplayName,
                 Password = Security.Sha256(register.Password),
                 //邮箱验证与邮箱唯一性问题
                 Email = register.Email,
                 //用户状态问题
                 Status = 0,
                 LoginIP = "",
                 LoginTime = DateTime.Now,
                 RegistrationTime = DateTime.Now
             };
             _user = userService.Add(_user);
             if (_user.UserID > 0)
             {
                 var _identity = userService.CreateIdentity(_user, DefaultAuthenticationTypes.ApplicationCookie);
                 AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                 AuthenticationManager.SignIn(_identity);
                 return RedirectToAction("Index", "Home");
             }
             else { ModelState.AddModelError("", "注册失败!"); }
         }
     }
     return View(register);
 }