Пример #1
0
 public ActionResult Register(MembersRegisterViewModel RegisterMember)
 {
     //判斷頁面資料中的密碼欄位輸入
     if (ModelState.IsValid)
     {
         //將頁面中的密碼欄位輸入
         RegisterMember.newMember.Password = RegisterMember.Password;
         //取得信箱驗證碼
         string AuthCode = mailService.GetValidateCode();
         //將信箱驗證碼填入
         RegisterMember.newMember.AuthCode = AuthCode;
         //呼叫Service註冊新會員
         membersService.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", "Members", new { Account = RegisterMember.newMember.Account, AuthCode = AuthCode })
         };
         //藉由Service將使用者資料填入驗證信範本中
         string MailBody = mailService.GetRegisterMailBody(TempMail, RegisterMember.newMember.Name, ValidateUrl.ToString().Replace("%3F", "?"));
         //呼叫Service寄出驗證信
         mailService.SendRegisterMailstring(MailBody, RegisterMember.newMember.Email);
         //TempData儲存註冊訊息
         TempData["RegisterState"] = "註冊成功,請去收信以驗證Email";
         //重新導向頁面
         return(RedirectToAction("RegisterResult"));
     }
     //未經驗證清空密碼相關欄位
     RegisterMember.Password      = null;
     RegisterMember.PasswordCheck = null;
     //將資料回填至View中
     return(View(RegisterMember));
 }
Пример #2
0
 public ActionResult Register(MembersRegisterViewModel RegisterMember)
 {
     //判斷頁面資料是否都經過驗證
     if (ModelState.IsValid)
     {
         if (RegisterMember.MembersImage != null)
         {
             //使用Html的ContentType進行檢查
             if (membersService.CheckImage(RegisterMember.MembersImage.ContentType))
             {
                 //取得檔名
                 string filename = Path.GetFileName(RegisterMember.MembersImage.FileName);
                 //將檔案和伺服器上路徑合併
                 string url = Path.Combine(Server.MapPath($@"~/Upload/Members/"), filename);
                 //將檔案儲存於伺服器上
                 RegisterMember.MembersImage.SaveAs(url);
                 //設定路徑
                 RegisterMember.newMember.Image = filename;
                 //將頁面中的密碼欄位輸入
                 RegisterMember.newMember.Password = RegisterMember.Password;
                 //取得信箱驗證碼
                 string AuthCode = mailService.GetValidateCode();
                 //將信箱驗證碼填入
                 RegisterMember.newMember.AuthCode = AuthCode;
                 //呼叫Service註冊新會員
                 membersService.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", "Members", new { Account = RegisterMember.newMember.Account, AuthCode = AuthCode })
                 };
                 //藉由Service將使用者資料填入驗證信範本中
                 string MailBody = mailService.GetRegisterMailBody(TempMail, RegisterMember.newMember.Name, ValidateUrl.ToString().Replace("%3F", "?"));
                 //呼叫Service寄出驗證信
                 mailService.SendRegisterMailstring(MailBody, RegisterMember.newMember.Email);
                 //TempData儲存註冊訊息
                 TempData["RegisterState"] = "註冊成功,請去收信以驗證Email";
                 //重新導向頁面
                 return(RedirectToAction("RegisterResult"));
             }
             else
             {
                 ModelState.AddModelError("MembersImage", "所上傳檔案不是圖片");
             }
         }
         else
         {
             ModelState.AddModelError("MembersImage", "請選擇上傳檔案");
             return(View(RegisterMember));
         }
     }
     //未經驗證清空密碼欄位
     RegisterMember.Password      = null;
     RegisterMember.PasswordCheck = null;
     return(View(RegisterMember));
 }
Пример #3
0
 public ActionResult Register(MembersRegisterViewModel RegisterMember)
 {
     //判斷頁面資料是否都經過驗證
     if (ModelState.IsValid)
     {
         //將頁面資料中的密碼欄位填入
         RegisterMember.newMember.Password = RegisterMember.Password;
         //呼叫Serrvice註冊新會員
         membersService.Register(RegisterMember.newMember);
         //重新導向頁面
         return(RedirectToAction("RegisterResult"));
     }
     //未經驗證清空密碼相關欄位
     RegisterMember.Password      = null;
     RegisterMember.PasswordCheck = null;
     //將資料回填至View中
     return(View("Login", RegisterMember));
 }