Ejemplo n.º 1
0
        public ActionResult ResetPassword(cvmResetPassword model)
        {
            if (!ModelState.IsValid) return View(model);

            //自定義檢查
            string str_password = "";
            using (Cryptographys cryp = new Cryptographys())
            { str_password = cryp.SHA256Encode(model.CurrentPassword); }
            bool bln_error = false;

            var check = db.Users
                .Where(m => m.mno == model.UserNo)
                .Where(m => m.password == str_password)
                .FirstOrDefault();
            if (check == null) { ModelState.AddModelError("", "目前密碼輸入錯誤!!"); bln_error = true; }
            if (bln_error) return View(model);

            str_password = model.NewPassword;
            var user = db.Users.Where(m => m.mno == model.UserNo).FirstOrDefault();
            if (user != null)
            {
                //密碼加密
                using (Cryptographys cryp = new Cryptographys())
                { str_password = cryp.SHA256Encode(str_password); }

                user.password = str_password;
                db.Configuration.ValidateOnSaveEnabled = false;
                db.SaveChanges();
                db.Configuration.ValidateOnSaveEnabled = true;
            }
            return RedirectToAction("RedirectToUserPage");
        }
Ejemplo n.º 2
0
        public ActionResult Login(cvmLogin model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Message = "Account or Password Error!!";
                return(View(model));
            }

            string str_password = model.UserPassword;

            using (Cryptographys cryp = new Cryptographys())
            {
                str_password = cryp.SHA256Encode(str_password);
            }

            var users = db.users
                        .Where(m => m.maccount == model.UserAccount)
                        .Where(m => m.mpassword == str_password)
                        .FirstOrDefault();

            if (users == null)
            {
                UserAccount.LogOut();
                FormsAuthentication.SignOut();
                ViewBag.Message = "帳號或密碼錯誤!";
                return(View(model));
            }

            UserAccount.Login(users, UserAccount.GetRoleNo(users.role_no));
            UserAccount.IsRememberMe = model.Remember;
            UserAccount.LoginAuthenticate();

            return(RedirectToAction("RedirectToUserPage"));
        }
Ejemplo n.º 3
0
        public ActionResult Login(cvmLogin model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            string str_password = model.Password;

            using (Cryptographys crpy = new Cryptographys())
            {
                str_password = crpy.SHA256Encode(str_password);
            }
            var users = db.Users
                        .Where(m => m.mno == model.UserNo)
                        .Where(m => m.password == str_password)
                        .FirstOrDefault();

            if (users == null)
            {
                return(View(model));
            }
            UserAccount.Login(model.UserNo, users.mname, UserAccount.GetRoleNo(users.role_no));

            return(RedirectToAction("RedirectToUserPage"));
        }
Ejemplo n.º 4
0
        public ActionResult Register(cvmRegister model)
        {
            if (!ModelState.IsValid) return View(model);

            //自定義檢查
            bool bln_error = false;
            var check = db.Users.Where(m => m.mno == model.mno).FirstOrDefault();
            if (check != null) { ModelState.AddModelError("mno", "帳號重覆註冊!!"); bln_error = true; }
            check = db.Users.Where(m => m.email == model.email).FirstOrDefault();
            if (check != null) { ModelState.AddModelError("email", "電子信箱重覆註冊!!"); bln_error = true; }
 
            if (bln_error) return View(model);

            //密碼加密
            using (Cryptographys cryp = new Cryptographys())
            {
                model.password = cryp.SHA256Encode(model.password);
                model.ConfirmPassword = model.password;
            }

            Users user = new Users();
            user.mno = model.mno;
            user.mname = model.mname;
            user.password = model.password;
            user.email = model.email;
            user.birthday = model.birthday;
            user.remark = model.remark;
            user.role_no = "Member";  
            user.varify_code = UserAccount.GetNewVarifyCode(); //產生驗證碼
            user.isvarify = 0;

            //寫入資料庫
            try
            {
                db.Configuration.ValidateOnSaveEnabled = false;
                db.Users.Add(user);
                db.SaveChanges();
                db.Configuration.ValidateOnSaveEnabled = true;
            }
            catch (Exception ex)
            {
                string str_message = ex.Message;
            }

            //寄出驗證信
            SendVerifyMail(model.email, user.varify_code);
            return RedirectToAction("SendEmailResult");
        }
Ejemplo n.º 5
0
        public ActionResult ResetPassword(int id)
        {
            bool status = false;

            using (dbcon db = new dbcon())
            {
                var model = db.users.Where(m => m.rowid == id).FirstOrDefault();
                if (model != null)
                {
                    using (Cryptographys crpy = new Cryptographys())
                    {
                        model.mpassword = crpy.SHA256Encode(model.mno);
                        db.SaveChanges();
                    }
                    status = true;
                }
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
Ejemplo n.º 6
0
        public ActionResult Register(cvmRegister model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //自定義檢查
            bool bln_error = false;
            var  user      = db.users.Where(m => m.maccount == model.maccount).FirstOrDefault();

            if (user != null)
            {
                ModelState.AddModelError("", "帳號重複註冊!"); bln_error = true;
            }
            user = db.users.Where(m => m.memail == model.memail).FirstOrDefault();
            if (user != null)
            {
                ModelState.AddModelError("", "電子信箱重複註冊!"); bln_error = true;
            }
            if (bln_error)
            {
                return(View(model));
            }

            //密碼加密
            using (Cryptographys cryp = new Cryptographys())
            {
                model.mpassword       = cryp.SHA256Encode(model.mpassword);
                model.ConfirmPassword = model.mpassword;
            }

            users new_user = new users();

            new_user.maccount    = model.maccount;
            new_user.mname       = model.mname;
            new_user.mpassword   = model.mpassword;
            new_user.memail      = model.memail;
            new_user.birthday    = model.birthday;
            new_user.remark      = model.remark;
            new_user.role_no     = "Member";                       //設定角色代號為 Member
            new_user.varify_code = UserAccount.GetNewVarifyCode(); //產生驗證碼
            new_user.isvarify    = 0;

            //寫入資料庫
            try
            {
                db.Configuration.ValidateOnSaveEnabled = false;
                db.users.Add(new_user);
                db.SaveChanges();
                db.Configuration.ValidateOnSaveEnabled = true;
            }
            catch (Exception ex)
            {
                string str_message = ex.Message;
            }

            //寄出驗證信
            SendVerifyMail(model.memail, new_user.varify_code);
            return(RedirectToAction("SendEmailResult"));
        }