Esempio n. 1
0
        public ActionResult RequestResetPassword(RequestResetPasswordViewModel vm)
        {
            if (ModelState.IsValid)
            {
                // Insert ResetPassword key into DB
                var tmp = string.Format("{0}{1}", Guid.NewGuid(), Guid.NewGuid());
                var resetPasswordKey = tmp.Replace("-", "");

                var feedback = _securityRepository.RequestResetPassword(vm.Email, resetPasswordKey);
                if (feedback.Success)
                {
                    // Send verification email
                    MailController mailController = new MailController();
                    vm.Username = feedback.Data.Username;
                    vm.ResetPasswordKey = resetPasswordKey;
                    vm.ResetPasswordLink = string.Format("http://{0}/account/resetpassword?key={1}", Request.Url.Authority,
                                                        resetPasswordKey);
                    try
                    {
                        mailController.ResetPasswordVerificationEmail(vm).Deliver();

                        return View("RequestPasswordSuccess");
                    }
                    catch
                    {
                        SetMessage("Có lỗi xảy ra. Hệ thống không thể gửi mail xác nhận quên mật khẩu cho bạn.", MessageType.Error);
                    }
                }
                else
                {
                    ModelState.AddModelError("", feedback.Message);
                }
            }

            return View(vm);
        }
Esempio n. 2
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var newUser = new User
                {
                    Email = model.Email,
                    Username = model.Username,
                    Password = model.Password
                };

                Feedback feedback = _securityRepository.Register(newUser);

                if (feedback.Success)
                {
                    // Send welcome email to user
                    MailController mailController = new MailController();
                    try
                    {
                        mailController.WelcomeEmail(model).Deliver();
                    }
                    catch
                    {
                        SetMessage("Có lỗi xảy ra. Hệ thống không thể gửi mail chúc mừng cho bạn.", MessageType.Error);
                    }
                    return View("WelcomeEmail", model);
                }
                else
                {
                    ModelState.AddModelError("", feedback.Message);
                }
            }

            return View(model);
        }