//密碼確認
        private bool passwordCheck(CRegisterModel p, string password)
        {
            //判斷DB裡的密碼資料與傳入密碼資料Hash後是否一致
            bool result = p.txtPassword.Equals(password);

            return(result);
        }
        //確認信箱是否重複註冊
        public bool accountCheck(string email)
        {
            CRegisterModel c = getAccount(email);
            //判斷是否查到資料
            bool result = (c == null);

            return(result);
        }
        //會員權限角色管理
        public string getRole(string email)
        {
            //初始角色
            string         Role = "User";
            CRegisterModel p    = getAccount(email);

            //判斷DB欄位,以確認是否為Admin
            if (p.isAdmin)
            {
                Role += "Admin";       //添加Admin
            }
            return(Role);
        }
        //信箱驗證碼驗證
        public string emailValidation(string email, string authCode)
        {
            CRegisterModel c = getAccount(email);
            //宣告驗證後訊息字串
            string validationStr = string.Empty;

            if (c != null)
            {
                dbJoutaEntities db = new dbJoutaEntities();
                tMember         t  = db.tMember.FirstOrDefault(k => k.f會員電子郵件 == email && k.f驗證碼 == authCode);
                t.f驗證碼        = "";
                validationStr = "信箱驗證成功,現在可以登入囉~";
            }
            return(validationStr);
        }
        //註冊新會員
        public void Register(CRegisterModel newMember)
        {
            //sql新增     isAdmin預設為0

            tMember t = new tMember();

            t.f會員電子郵件 = newMember.txtEmail;
            t.f會員帳號   = newMember.txtEmail;
            t.f會員名稱   = newMember.txtNickname;
            t.f會員密碼   = newMember.txtPassword;
            t.f驗證碼    = newMember.fActivationCode;
            t.isAdmin = false;
            db.tMember.Add(t);
            db.SaveChanges();
        }
        //取得公開資料
        public CRegisterModel getAccount_openSource(string email)
        {
            CRegisterModel c = new CRegisterModel();
            tMember        t = db.tMember.FirstOrDefault(k => k.f會員電子郵件 == email);

            try
            {
                c.txtEmail    = t.f會員電子郵件;
                c.txtNickname = t.f會員名稱;
            }
            catch (Exception)
            {
                //查無資料
                c = null;
            }
            return(c);
        }
        //更改密碼
        public string ChangePassword(string email, string password, string newPassword)
        {
            CRegisterModel p = getAccount(email);

            //確認舊密碼的正確性
            if (passwordCheck(p, password))
            {
                p.txtPassword = newPassword;
                tMember t = db.tMember.FirstOrDefault(k => k.f會員密碼 == p.txtPassword);
                db.tMember.Add(t);
                db.SaveChanges();
                return("密碼修改成功");
            }
            else
            {
                return("原密碼輸入錯誤");
            }
        }
Exemplo n.º 8
0
        public ActionResult Register(CRegisterModel p)
        {
            if ((p == null) && (!ModelState.IsValid))
            {
                return(View());
            }
            //判斷資料是否通過驗證
            if (ModelState.IsValid)
            {
                //將頁面資料中的密碼填入
                //p.newMember.txtPassword = p.txtPassword;
                //取得信箱驗證碼
                string AuthCode = mailService.getValidationCode();
                //填入驗證碼
                p.fActivationCode = AuthCode;
                //呼叫service註冊新會員
                membersService.Register(p);
                string tempMail = System.IO.File.ReadAllText(
                    Server.MapPath("~/Views/Shared/RegisterEmailTemplate.html"));

                //宣告Email驗證用Url
                UriBuilder validateUrl = new UriBuilder(Request.Url)
                {
                    Path = Url.Action("emailValidation", "Home", new
                    {
                        email    = p.txtEmail,
                        authCode = AuthCode
                    })
                };
                //將資料寫入信中
                string MailBody = mailService.getRegisterMailBody(tempMail, p.txtNickname, validateUrl.ToString().Replace("%3F", "?"));
                //寄信
                mailService.sendRegisterMail(MailBody, p.txtEmail);
                //以tempData儲存註冊訊息
                TempData["RegisterState"] = "註冊成功,請去收取驗證信";
                return(RedirectToAction("RegisterResult"));
            }
            //未經驗證清空密碼相關欄位
            p.txtPassword         = null;
            p.txtPassword_confirm = null;
            //資料回填至view中
            return(View(p));
        }
        //藉由信箱取得單筆資料(全部資料)
        private CRegisterModel getAccount(string email)
        {
            CRegisterModel c = new CRegisterModel();
            tMember        t = db.tMember.FirstOrDefault(k => k.f會員電子郵件 == email);

            try
            {
                c.txtEmail        = t.f會員電子郵件;
                c.txtNickname     = t.f會員名稱;
                c.txtPassword     = t.f會員密碼;
                c.fActivationCode = t.f驗證碼;
                c.isAdmin         = Convert.ToBoolean(t.isAdmin);
            }
            catch (Exception)
            {
                //查無資料
                c = null;
            }
            return(c);
        }
Exemplo n.º 10
0
        public string LoginCheck(string email, string password)
        {
            //取得傳入email的會員資料
            CRegisterModel p = getAccount(email);

            //判斷是否有此人
            if (p != null)
            {
                p.fActivationCode = null;
                //進行信箱密碼驗證
                if (passwordCheck(p, password))
                {
                    return("");
                }
                else
                {
                    return("密碼輸入錯誤");
                }
            }
            else
            {
                return("此信箱尚未註冊,請去註冊");
            }
        }
Exemplo n.º 11
0
 //判斷信箱是否被註冊過
 public JsonResult accountCheck(CRegisterModel p)
 {
     //呼叫service來判斷,並回傳結果
     return(Json(membersService.accountCheck(p.txtEmail), JsonRequestBehavior.AllowGet));
 }