public ActionResult Register() { var registerInfo = new RegisterInfoModel(); // Get list of city var cityBAL = new CityBAL(); registerInfo.LstCity = cityBAL.GetAll(); return(View(registerInfo)); }
public ActionResult Register(RegisterInfoModel model) { var googleCaptchaBAL = new GoogleCaptchaBAL(); if (googleCaptchaBAL.Authenticate(Request["g-recaptcha-response"]) && ModelState.IsValid) { try { // Tách lấy username của người dùng var userName = model.UserEmail.Split('@')[0]; // Kiểm tra thông tin người dùng này đã tồn tại chưa // Nếu tồn tại rồi thì đánh chỉ số cho người dùng đó var id = WebSecurity.GetUserId(userName); if (id > 0) { var indexUser = (new Random()).Next(1, 10000); userName += indexUser.ToString(); } model.UserName = userName; // Tạo tài khoản var tokenKey = WebSecurity.CreateUserAndAccount(model.UserName, model.Password, null, true); // Bổ sung thông tin tài khoản tài khoản var userInformationBAL = new UserInformationBAL(); userInformationBAL.Create(new UserInformation() { FirstName = model.FirstName, LastName = model.LastName, UserEmail = model.UserEmail, UserName = model.UserName, CityCode = model.CityCode }); //Gui mail yeu cau kich hoat tai khoan var mailConfirmAccountBAL = new MailConfirmAccountBAL(); mailConfirmAccountBAL.SendConfirmMail(model.UserEmail, model.UserName, tokenKey); return(RedirectToAction("ActivateNotification", "Account", new { username = model.UserEmail })); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // Get list of city var cityBAL = new CityBAL(); model.LstCity = cityBAL.GetAll(); // If we got this far, something failed, redisplay form return(View(model)); }
public ResponseModel Register(RegisterInfoModel model) { var response = new ResponseModel(); // Validate 1 số các thông tin //Họ và tên bắt buộc nhập if (string.IsNullOrEmpty(model.FirstName)) { response.Code = SystemStatusCode.NotValid.GetHashCode(); response.Message = "Tên của người dùng bắt buộc nhập"; } if (string.IsNullOrEmpty(model.LastName)) { response.Code = SystemStatusCode.NotValid.GetHashCode(); response.Message = "Họ của người dùng bắt buộc nhập"; } if (string.IsNullOrEmpty(model.UserEmail) || !Helper.IsValidMail(model.UserEmail)) { response.Code = SystemStatusCode.NotValid.GetHashCode(); response.Message = "Email của người dùng bắt buộc nhập"; } return(response); }