//判斷註冊帳號是否已被註冊過Action public JsonResult AccountCheck(MemberRegisterView RegisterMember) { //呼叫Service來判斷,並回傳結果 return(Json(memberService.AccountCheck( RegisterMember.newMember.Account), JsonRequestBehavior.AllowGet)); }
public ActionResult Register(MemberRegisterView ViewData) { if (ModelState.IsValid) { ViewData.MemberData.Password = ViewData.Password; string AuthCode = mailService.GetAuthCode(); ViewData.MemberData.AuthCode = AuthCode; memberService.RegisterNewMember(ViewData.MemberData); //寄送驗證信 //讀取範本檔 string TempMail = System.IO.File.ReadAllText(Server.MapPath("~/Views/Shared/RegisterEmailTemplate.html")); UriBuilder ValidateUrl = new UriBuilder(Request.Url) { Path = Url.Action("EmailValidate", "Member", new { UserName = ViewData.MemberData.Name, AuthCode = ViewData.MemberData.AuthCode }) }; //藉 Service 將使用者資料填入驗證信 string MailBody = mailService.GetRegisterMailBody(TempMail, ViewData.MemberData.Name, ValidateUrl.ToString().Replace("%3F", "?")); //藉 Service 寄出認證信 mailService.SendRegisterMail(MailBody, ViewData.MemberData.Email); //使用 TempData 儲存註冊資訊 TempData["RegisterState"] = "註冊成功,請至註冊信箱收取驗證信!"; //重新導向 return(RedirectToAction("RegisterResult")); } ViewData.Password = null; ViewData.PasswordChek = null; return(View(ViewData)); }
public ActionResult Register(MemberRegisterView RegisterMember) { if (ModelState.IsValid) { string AuthCode = mailService.GetValidateCode(); string TempMail = System.IO.File.ReadAllText(Server.MapPath("~/Views/Shared/RegisterEmailTemplate.html")); RegisterMember.newMember.Password = RegisterMember.Password; RegisterMember.newMember.AuthCode = AuthCode; memberService.Register(RegisterMember.newMember); UriBuilder ValidateUrl = new UriBuilder(Request.Url) { Path = Url.Action("EmailValidate", "Member", new { UserName = RegisterMember.newMember.Account, AuthCode = AuthCode }) }; string MailBody = mailService.GetRegisterMailBody(TempMail, RegisterMember.newMember.Name, ValidateUrl.ToString().Replace("%3F", "?")); mailService.SendRegisterMail(MailBody, RegisterMember.newMember.Email); TempData["RegisterState"] = "註冊成功,請去收信以驗證Email"; return(RedirectToAction("RegisterResult")); } RegisterMember.Password = null; RegisterMember.PasswordCheck = null; return(View(RegisterMember)); }
public ActionResult Register(MemberRegisterView registerView) { if (ModelState.IsValid) { registerView.newMember.Password = registerView.Password; string AuthCode = mailService.GetVaildCode(); registerView.newMember.AuthCode = AuthCode; memberService.Register(registerView.newMember); string Url = string.Format("http://localhost:57952/Member/EmailValidate?UserName={0}&AuthCode={1}", registerView.newMember.Account, AuthCode); mailService.SendRegisterMail(Url, registerView.newMember.Email); TempData["RegisterSatae"] = "註冊成功,請去收Emial驗證信"; return(RedirectToAction("RegisterResult")); } return(View(registerView)); }
public ActionResult Register(MemberRegisterView RegisterMember) { if (service.AccountCheck(RegisterMember.UserName) || service.EmailCheck(RegisterMember.Email)) { return(Json("資料重複")); } if (MemberMethod.IsValidEmail(RegisterMember.Email) && MemberMethod.IsValidPhone(RegisterMember.Phone)) { string guid = Guid.NewGuid().ToString("N"); Photo photo = new Photo { Photo1 = db.Photos.Find(1).Photo1, CreateDate = DateTime.Now }; db.Photos.Add(photo); db.SaveChanges(); RegisterMember.newMember = new User() { UserName = RegisterMember.UserName, UserPassword = MemberMethod.HashPw(RegisterMember.UserPassword, guid), Email = RegisterMember.Email, GUID = guid, Phone = RegisterMember.Phone, RegistrationDate = DateTime.Now, Enabled = true, RegionID = RegisterMember.Region, OauthType = "N", PhotoID = photo.PhotoID, Address = RegisterMember.Address, Gender = RegisterMember.Gender.Equals("male"), VerificationCode = String.Empty, Destination = "." }; if (service.Register(RegisterMember.newMember)) { return(Json("成功")); } else { return(Json("失敗")); } } else { return(Json("資料格式不正確")); } }
public ActionResult Register(MemberRegisterView RegisterMember) { var isSuccess = true; var returnData = new { // 成功與否 IsSuccess = isSuccess, // ModelState錯誤訊息 ModelStateErrors = ModelState.Where(x => x.Value.Errors.Count > 0) .ToDictionary(k => k.Key, k => k.Value.Errors.Select(e => e.ErrorMessage).ToArray()) }; if (ModelState.IsValid) { //將頁面資料的密碼欄位填入 RegisterMember.NewMember.Password = RegisterMember.Password; //取得信箱驗證碼 string AuthCode = mailService.GetValidateCode(); //信箱驗證碼填入 RegisterMember.NewMember.AuthCode = AuthCode; //呼叫service註冊新會員 portalDBService.Register(RegisterMember.NewMember); //取得驗證信範本 string TempMail = System.IO.File.ReadAllText( Server.MapPath("~/Views/Shared/RegisterEmailTemplate.html")); //宣告email驗證用的url UriBuilder ValidateUrl = new UriBuilder(Request.Url) { Path = Url.Action("EmailValidate", "Portal", new { RegisterMember.NewMember.UserName, AuthCode }) }; //藉由service將使用者資料填入驗證信 string MailBody = mailService.GetRegisterMailBody(TempMail , RegisterMember.NewMember.Id.ToString() , RegisterMember.NewMember.UserName , ValidateUrl.ToString().Replace("%3F", "?")); mailService.SendRegisterMail(MailBody, RegisterMember.NewMember.Email); //存儲註冊信息 TempData["RegisterState"] = "註冊成功,請去收信驗證Email"; return(RedirectToAction("RegisterResult")); } RegisterMember.Password = null; RegisterMember.PasswordCheck = null; return(View(RegisterMember)); }
[HttpPost] //設定此Action只接受頁面POST資料傳入 public ActionResult Register(MemberRegisterView RegisterMember) { //判斷頁面資料是否都經過驗證 if (ModelState.IsValid) { //將頁面資料中的密碼欄位填入 RegisterMember.newMember.Password = RegisterMember.Password; //取得信箱驗證碼 string AuthCode = mailService.GetValidateCode(); //將信箱驗證碼填入 RegisterMember.newMember.AuthCode = AuthCode; //呼叫Serrvice註冊新會員 memberService.Register(RegisterMember.newMember); //取得寫好的驗證信範本內容 string TempMail = System.IO.File.ReadAllText( Server.MapPath("~/Views/Shared/RegisterEmailTemplate.html")); //宣告Email驗證用的Url UriBuilder ValidateUrl = new UriBuilder(Request.Url) { Path = Url.Action("EmailValidate", "Member" , new { UserName = RegisterMember.newMember.Account , AuthCode = AuthCode }) }; //藉由Service將使用者資料填入驗證信範本中 string MailBody = mailService.GetRegisterMailBody(TempMail , RegisterMember.newMember.Name , ValidateUrl.ToString().Replace("%3F", "?")); //呼叫Service寄出驗證信 mailService.SendRegisterMail(MailBody, RegisterMember.newMember.Email); //用TempData儲存註冊訊息 TempData["RegisterState"] = "註冊成功,請去收信以驗證Email"; //重新導向頁面 return(RedirectToAction("RegisterResult")); } //未經驗證清空密碼相關欄位 RegisterMember.Password = null; RegisterMember.PasswordCheck = null; //將資料回填至View中 return(View(RegisterMember)); }
public ActionResult Register(MemberRegisterView memberRegister) { //TODO: 驗證帳號重複 if (ModelState.IsValid) { Member member = new Member(); member.Email = memberRegister.Email; member.Password = memberRegister.Password; member.Name = memberRegister.Name; member.NickName = memberRegister.NickName; member.Birthday = memberRegister.Birthday; member.Phone = memberRegister.Phone; member.ValidateCode = ValidateHelper.GetValidateCode(); member.Id = Guid.NewGuid(); string template = System.IO.File.ReadAllText(Server.MapPath("~/Views/MailTemplate/RegisterMailTemplate.html")); UriBuilder validateUrl = new UriBuilder(Request.Url) { Path = Url.Action("EmailValidate", "Account", new { memberId = member.Id, validateCode = member.ValidateCode }) }; string mailBody = mailService.GetValidateMailBody(template, member.Name, validateUrl.ToString().Replace("%3F", "?")); //存入資料庫與寄送驗證信 string result = string.Empty; string message = memberService.Register(member); if (message != string.Empty) { TempData["ErrorMsg"] = message; } else if (!mailService.SendMail(member.Email, mailBody, "會員註冊信")) { TempData["ErrorMsg"] = "寄送驗證信失敗"; } else { TempData["SuccessMsg"] = "註冊成功,請去收驗證信"; } return(View("Message")); } return(View(memberRegister)); }
public JsonResult AccountCheck(MemberRegisterView registerMember) { return(Json(memberService.AccountCheck(registerMember.newMember.AuthCode), JsonRequestBehavior.AllowGet)); }
public ActionResult Register() { var view = new MemberRegisterView(); return(View(view)); }
//確認帳號是否註冊過 public JsonResult AccountCheck(MemberRegisterView RegisterMember) { return(Json(portalDBService.EmailCheck(RegisterMember.NewMember.Email), JsonRequestBehavior.AllowGet)); }