Example #1
0
        public User LoginUser(LoginViewModel login)
        {
            string hashPassword = HashCodeHelper.HashPassword(login.Password);
            string email        = FixText.FixEmail(login.Email);

            return(_db.Users.SingleOrDefault(u => u.Email == email && u.Password == hashPassword));
        }
Example #2
0
        public User LoginUser(AccountViewModel.LoginViewModel login)
        {
            string hashPassword = PasswordHelper.EncodePasswordMd5(login.Password);
            string email        = FixText.FixEmail(login.Email);

            return(_context.Users.SingleOrDefault(u => u.Email == email && u.Password == hashPassword));
        }
Example #3
0
        public IActionResult ForgotPassword(ForgotViewModel forgotView)
        {
            if (!ModelState.IsValid)
            {
                return(View(forgotView));
            }
            string fixemail = FixText.FixEmail(forgotView.Email);
            User   user     = _userService.GetUserByEmail(fixemail);

            if (user == null)
            {
                ModelState.AddModelError("Email", "کاربری یافت نشد");
                return(View(forgotView));
            }
            string body = _viewRenderService.RenderToStringAsync("_ForgotPasswordEmail", user);

            SendEmail.Send(user.Email, "تغییر کلمه عبور", body);
            ViewBag.IsSuccess = true;
            return(View());
        }
Example #4
0
        public IActionResult Register(AccountViewModel.RegisterViewModel register)
        {
            if (!ModelState.IsValid)
            {
                return(View(register));
            }


            if (_userService.isExistUserName(register.UserName))
            {
                ModelState.AddModelError("UserName", "نام کاربری معتبر نمی باشد");
                return(View(register));
            }

            if (_userService.isExistEmail(FixText.FixEmail(register.Email)))
            {
                ModelState.AddModelError("Email", "ایمیل معتبر نمی باشد");
                return(View(register));
            }


            DataLayer.Entities.User.User user = new User()
            {
                ActiveCode   = NameGenerator.GenerateUniqCode(),
                Email        = FixText.FixEmail(register.Email),
                IsActive     = false,
                Password     = PasswordHelper.EncodePasswordMd5(register.Password),
                RegisterDate = DateTime.Now,
                UserAvatar   = "Defult.jpg",
                UserName     = register.UserName
            };
            _userService.AddUser(user);
            // Active email
            string body = _viewRenderService.RenderToStringAsync("_ActiveEmail", user);

            SendEmail.Send(user.Email, "فعالسازی", body);
            return(View("SuccessRegister", user));
        }
Example #5
0
        public IActionResult Register(RegisterViewModel register)
        {   //agar etebar sangi haye man anjam dade nashode bod return kon view
            if (!ModelState.IsValid)
            {
                return(View(register));
            }

            if (_userService.IsExistUsername(register.Username))
            {
                ModelState.AddModelError("username", "نام کاربری معتبر نمی باشد");
                return(View(register));
            }
            if (_userService.IsExistEmail(FixText.FixEmail(register.Email)))
            {
                ModelState.AddModelError("Email", "ایمیل معتبر نمی باشد");
                return(View(register));
            }
            User user = new User();

            user.ActiveCode   = NameGenerator.GenerateUniqCode();
            user.Email        = FixText.FixEmail(register.Email);
            user.Username     = register.Username;
            user.IsActive     = false;
            user.Password     = HashCodeHelper.HashPassword(register.Password);
            user.RegisterDate = DateTime.Now;
            user.UserAvatar   = "Defult.jpg";

            _userService.AddUser(user);
            #region SendActivationEmail

            string body = _viewRenderService.RenderToStringAsync("_ActiveEmail", user);
            SendEmail.Send(user.Email, "فعال سازی تاپ لرن", body);



            #endregion
            return(View("SuccessRegister", user));
        }
Example #6
0
        public ActionResult ForgotPassword(AccountViewModel.ForgotPasswordViewModel forgot)
        {
            if (!ModelState.IsValid)
            {
                return(View(forgot));
            }

            string fixedEmail = FixText.FixEmail(forgot.Email);

            DataLayer.Entities.User.User user = _userService.GetUserByEmail(fixedEmail);

            if (user == null)
            {
                ModelState.AddModelError("Email", "کاربری یافت نشد");
                return(View(forgot));
            }

            string bodyEmail = _viewRenderService.RenderToStringAsync("_ForgotPassword", user);

            SendEmail.Send(user.Email, "بازیابی حساب کاربری", bodyEmail);
            ViewBag.IsSuccess = true;

            return(View());
        }