public UserInfoPrincipal(string userName) { UserBusinessLogic userLogic = new UserBusinessLogic(); var user = userLogic.GetUserInfoByUserName(userName); this.identity = new UserInfoIdentity(user.ID, user.UserName, user.IsAdmin); }
public ActionResult Register(UserRegisterModel userRegister) { if (!ModelState.IsValid) { return(View()); } List <string> msgList = new List <string>(); string verifyCode = Session["ValidateCode"] as string; if (userRegister.VerifyCode != verifyCode) { msgList.Add("验证码输入错误"); } if (!Utility.IsEmail(userRegister.Email)) { msgList.Add("Email输入错误"); } var userinfo = userBusinessLogic.GetUserInfoByUserName(userRegister.UserName); if (userinfo != null) { msgList.Add("用户名已存在"); } userinfo = userBusinessLogic.GetUserInfoByEmail(userRegister.Email); if (userinfo != null) { msgList.Add("Email已存在"); } if (msgList.Count > 0) { ViewBag.MsgList = msgList; return(View()); } T_User userDomain = new T_User() { UserName = Sanitizer.GetSafeHtmlFragment(userRegister.UserName), Email = Sanitizer.GetSafeHtmlFragment(userRegister.Email), LastLogin = DateTime.Now, NikeName = "", Password = Md5.GetMd5(userRegister.Password), Photo = "", RegisterDate = DateTime.Now, IsAdmin = 0, State = 1 }; int userId = userBusinessLogic.AddUser(userDomain); if (userId > 0) { // 发送注册成功提醒邮件 NoticeMail.SendWelcomeMail(userDomain.UserName, userDomain.Email); msgList.Add("注册成功!"); ViewBag.MsgList = msgList; //return RedirectToAction("Profile", "User", null); } //Response.Write("<script>alert('注册成功,请登录!');</script>"); return(View()); }