Beispiel #1
0
        public IActionResult Register(RegisterViewModel register)
        {
            if (ModelState.IsValid)
            {
                if (_iuser.IsMobileNumberExist(register.Mobile))
                {
                    ModelState.AddModelError("Mobile", "شما قبلا ثبت نام کرده اید");
                    return(RedirectToAction("Login"));
                }
                else
                {
                    User user = new User()
                    {
                        IsActive = false,
                        Mobile   = register.Mobile,
                        Code     = CodeGenerators.ActiveCode(),

                        Password = HashGeneretors.EncodingPassWithMd5(register.Password),
                        RoleId   = 2,
                    };

                    _iuser.AddUser(user);
                    SMS sms = new SMS();
                    sms.Send(user.Mobile, "  کد فعال سازی  " + user.Code);
                    return(RedirectToAction("Active"));
                }
            }
            else
            {
                return(View(register));
            }
        }
Beispiel #2
0
        public bool ResetPassword(string activeCode, string password)
        {
            var user = _Context.Users.FirstOrDefault(u => u.Code == activeCode && u.IsActive == true);

            if (user != null)
            {
                string HashPassword = HashGeneretors.EncodingPassWithMd5(password);
                user.Password = HashPassword;
                user.Code     = CodeGenerators.ActiveCode();

                _Context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
0
        public User LoginUser(string mobileNumber, string password)
        {
            string hashPassword = HashGeneretors.EncodingPassWithMd5(password);

            return(_Context.Users.FirstOrDefault(u => u.Mobile == mobileNumber && u.Password == hashPassword));
        }