Exemplo n.º 1
0
        //用戶登入驗證
        private bool ValidateLogin(string fAccount, string fPassword)
        {
            //用戶密碼加密後處理
            //string strHashPassword = HashPassword(fPassword);
            string strHashPassword = fPassword;

            using (dbCustomerEntities db = new dbCustomerEntities())
            {
                //取得符合條件單筆資料
                Member member = db.Member.Where(a => a.fAccount == fAccount && a.fPassword == fPassword).FirstOrDefault();
                if (member != null)
                {
                    //會員未點擊驗證碼連結
                    if (member.fAuthCode != null)
                    {
                        ModelState.AddModelError("account", "信箱尚未驗證成功");
                        return(false);
                    }
                    //若用戶為管理者
                    if (member.fRole == 3)
                    {
                        strRole = "Admin";
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Exemplo n.º 2
0
 //註冊驗證
 public ActionResult Verify(string AuthCode)
 {
     using (dbCustomerEntities db = new dbCustomerEntities())
     {
         var memberData = db.Member.Where(a => a.fAuthCode == AuthCode).FirstOrDefault();
         if (memberData != null)
         {
             ViewData["Result"]   = "會員驗證成功";
             memberData.fAuthCode = null;
             db.SaveChanges();
         }
         else
         {
             ViewData["Result"] = "找不到此驗證碼,請確認是否驗證過?";
         }
     }
     return(View());
 }
Exemplo n.º 3
0
 public ActionResult Register([Bind(Exclude = "buildTime,authCode,Role")] CRegister member)
 {
     if (ModelState.IsValid)
     {
         try
         {
             using (dbCustomerEntities db = new dbCustomerEntities())
             {
                 //當用戶已存在
                 if (db.Member.Where(a => a.fAccount == member.account).FirstOrDefault() != null)
                 {
                     //設定模型驗證欄位狀態失敗顯示訊息
                     ModelState.AddModelError("account", "您註冊的帳號已經被使用,請重新設定");
                     //回傳模型檢視結果
                     return(View(member));
                 }
                 //宣告與建構交易式物件操作案例並自動釋放占用資源 => 確保資料可以寫入資料庫且必須完成
                 using (TransactionScope ts = new TransactionScope())
                 {
                     memberservice.Register(member);
                     //寄信
                     ////取得信箱驗證碼
                     //string AuthCode = mailservice.getValidationCode();
                     ////填入驗證碼
                     //member.authCode = AuthCode;
                     ////取得驗證信範本
                     //string tempmail = System.IO.File.ReadAllText(
                     //    Server.MapPath("~/Views/Shared/registerEmailTemplate.html"));
                     ////宣告email驗證用的url
                     //UriBuilder vUri = new UriBuilder(Request.Url)
                     //{
                     //    Path = Url.Action("emailValidate", "Home", new
                     //    {
                     //        account = member.account,
                     //        authcode = AuthCode
                     //    })
                     //};
                     ////填入驗證信
                     //string mailBody = mailservice.getRegisterMailBody(tempmail, member.name, vUri.ToString().Replace("%3F", "?"));
                     ////寄信
                     //mailservice.sendRegisterMail(mailBody, member.email);
                     ////用tempData儲存註冊訊息
                     ///TempData["RegisterState"] = "註冊成功,請去收信以驗證email";
                     TempData["RegisterState"] = "註冊成功,請重新登入";
                     ////設定所有交易皆已完成
                     ts.Complete();
                     return(RedirectToAction("registerResult", "Home"));
                 }
             }
         }
         catch (SmtpException)
         {
             ModelState.AddModelError("email", "系統發生異常,目前無法寄送驗證信,請稍後再試");
         }
         catch (DbEntityValidationException e)
         {
             foreach (var eve in e.EntityValidationErrors)
             {
                 Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                   eve.Entry.Entity.GetType().Name, eve.Entry.State);
                 foreach (var ve in eve.ValidationErrors)
                 {
                     Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                       ve.PropertyName, ve.ErrorMessage);
                 }
             }
             throw;
         }
         return(RedirectToAction("Login"));
     }
     else
     {
         //未經驗證清空密碼相關欄位
         member.password         = null;
         member.password_confirm = null;
         return(View(member));
     }
 }