Esempio n. 1
0
        public async Task <ActionResult> UserAccountEmail([Bind(Include = "EmailAddress")] UserEmailViewModel model)
        {
            ViewBag.UserName = User.Identity.Name;

            if (!ModelState.IsValid)
            {
                return(View("Manage", model));
            }

            // make sure no other accounts use this email address
            var existingAccount = await UserManager.FindByEmailAsync(model.EmailAddress);

            if (existingAccount != null)
            {
                ViewBag.StatusMessage = "This email address is already in use.";
                return(View("Manage", model));
            }

            // save changes
            var result = await UserManager.SetEmailAsync(User.Identity.GetUserId(), model.EmailAddress);

            if (result.Succeeded)
            {
                return(RedirectToAction("Manage"));
            }
            AddErrors(result);
            return(View("Manage", model));
        }
Esempio n. 2
0
        public ActionResult PartialEmail(string id)
        {
            UserEmailViewModel model = new UserEmailViewModel();

            model.UserId   = int.Parse(id);
            model.UserName = System.Web.HttpContext.Current.Request.Cookies["User"].Value;
            return(View(model));
        }
Esempio n. 3
0
        public JsonResult CheckEmailStatus([FromBody] UserEmailViewModel email)
        {
            if (_userDomainService.IsValidUserEmail(email.Email))
            {
                return(Json(string.Empty));
            }

            return(Json(ErrorMessages.NoUserWithEmail));
        }
Esempio n. 4
0
        public JsonResult SendRecoveryEmail([FromBody] UserEmailViewModel email)
        {
            try
            {
                _userDomainService.SendPasswordRecoveryEmail(GetUri(), email.Email);

                return(Json(string.Empty));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
        }
        public async Task <IActionResult> SendPasswordResetLink([FromBody] UserEmailViewModel model)
        {
            User user = await _repository.GetUserManager().FindByEmailAsync(model.Email);

            if (user != null)
            {
                var token   = _repository.GetUserManager().GeneratePasswordResetTokenAsync(user).Result;
                var url     = $"https://app.example.com/reset-password?email={model.Email}&token={token}";
                var message = $"<a href='{url}'>Click to reset password!</a>";
                await _emailService.SendEmailAsync(user.Email, "Password reset request", message);
            }
            return(NoContent());
        }
Esempio n. 6
0
        public ActionResult UserAccountEmail()
        {
            var existingEmail = UserManager.GetEmail(User.Identity.GetUserId());

            if (existingEmail == null)
            {
                return(PartialView("_ChangeAccountEmail"));
            }

            var userEmailViewModel = new UserEmailViewModel
            {
                EmailAddress = existingEmail
            };

            return(PartialView("_ChangeAccountEmail", userEmailViewModel));
        }
Esempio n. 7
0
        public async Task <ActionResult> UserAccountEmail([Bind(Include = "EmailAddress")] UserEmailViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Manage", model));
            }

            // save changes
            var result = await UserManager.SetEmailAsync(User.Identity.GetUserId(), model.EmailAddress);

            if (result.Succeeded)
            {
                return(RedirectToAction("Manage"));
            }
            AddErrors(result);
            return(View("Manage", model));
        }
Esempio n. 8
0
        async Task SendWelcomeMail(UserEmailViewModel model)
        {
            if (string.IsNullOrEmpty(model.UserEmail))
            {
                return;
            }

            try
            {
                var mailUser = new MailAddress(model.UserEmail);
                var subject  = String.Format("{0}, Welcome !", AppConfig.Settings.AppName);
                await Mailer.SendAsync("UserWelcome", model, subject, mailUser);
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            }
        }
        public async Task <ActionResult> UserAccountEmail([Bind("EmailAddress")] UserEmailViewModel model)
        {
            ViewBag.UserName = User.Identity.Name;

            if (!ModelState.IsValid)
            {
                return(View("Manage", model));
            }

            if (!String.IsNullOrEmpty(model.EmailAddress))
            {
                // make sure no other accounts use this email address
                var existingAccount = await UserManager.FindByEmailAsync(model.EmailAddress);

                if (existingAccount != null)
                {
                    if (existingAccount.UserName == User.Identity.Name)
                    {
                        //we have the current user with the same email address, abort
                        return(View("Manage", model));
                    }
                    else
                    {
                        ViewBag.StatusMessage = "This email address is already in use.";
                        return(View("Manage", model));
                    }
                }
            }

            //find current user
            var currentUser = await UserManager.FindByNameAsync(User.Identity.Name);

            // save changes
            var result = await UserManager.SetEmailAsync(currentUser, model.EmailAddress);

            if (result.Succeeded)
            {
                return(RedirectToAction("Manage"));
            }
            AddErrors(result);
            return(View("Manage", model));
        }
        public async Task <ActionResult> GetUserAccountEmail()
        {
            //CORE_PORT: Changes in User Manager
            //TODO: This code needs to be unit tested
            var user = await UserManager.FindByNameAsync(User.Identity.Name);

            var existingEmail = user.Email;

            if (existingEmail == null)
            {
                return(PartialView("_ChangeAccountEmail"));
            }

            var userEmailViewModel = new UserEmailViewModel
            {
                EmailAddress = existingEmail
            };

            return(PartialView("_ChangeAccountEmail", userEmailViewModel));
        }
        public async Task <IActionResult> UserEmail(UserEmailViewModel userEmailViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(userEmailViewModel));
            }

            // ------- get user object from the storage
            var applicationUser = await _userManager.GetUserAsync(User);



            if (applicationUser?.Email == userEmailViewModel.Email)
            {
                var result = await _userManager.CheckPasswordAsync(applicationUser, userEmailViewModel.Password);

                if (result)
                {
                    var token = await _userManager.GenerateChangeEmailTokenAsync(applicationUser, userEmailViewModel.NewEmail);

                    var confirmationLink = Url.Action(nameof(UserEmailConfirm), "Auth", new { token, email = userEmailViewModel.NewEmail }, Request.Scheme);

                    var message = new Message(new string[] { applicationUser?.Email }, "Confirmation email link", confirmationLink, null);
                    await _emailSender.SendEmailAsync(message);

                    return(RedirectToAction(nameof(SuccessUserEmail)));
                }
                else
                {
                    ModelState.TryAddModelError("", "your credentials are incorrect");

                    return(View(userEmailViewModel));
                }
            }

            ModelState.TryAddModelError("", "your credentials are incorrect");

            return(View(userEmailViewModel));
        }
Esempio n. 12
0
        public async Task <IActionResult> UpdateEmail([FromRoute] string id, [FromBody] UserEmailViewModel viewModel)
        {
            User user = await repository.GetByIdAsync <User>(id, _includeProperties);

            if (user == null)
            {
                return(NotFound(new { message = "User does not exist!" }));
            }
            if (!HttpContext.User.IsInRole("admin"))
            {
                // only admin or current user can update current user's email
                if (!HttpContext.User.HasClaim(c => c.Type == ClaimTypes.NameIdentifier && c.Value == user.Id))
                {
                    return(Forbid());
                }
            }
            if (viewModel.Email != user.Email)
            {
                if (await repository.GetUserManager().FindByEmailAsync(viewModel.Email) != null)
                {
                    ModelState.AddModelError("email", "Email is already in use");
                    return(BadRequest(ModelState));
                }
            }
            user.Email      = viewModel.Email;
            user.ModifiedAt = DateTime.UtcNow;
            var result = await repository.GetUserManager().UpdateAsync(user);

            if (!result.Succeeded)
            {
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("email", error.Description);
                }
                return(BadRequest(ModelState));
            }
            return(NoContent());
        }
Esempio n. 13
0
        public ActionResult EditEmail(UserEmailViewModel model)
        {
            try
            {
                UserDto   dto = new UserDto();
                Message   msg = new Message();
                DataTable dt  = CMSService.SelectOne("User", "CMSUser", "UserName!='" + model.UserName + "' and UserEmail='" + model.UserEmail + "'");
                if (dt.Rows.Count > 0)
                {
                    msg.MessageStatus = "Error";
                    msg.MessageInfo   = "此邮箱已经被其他用户占用。";
                    ViewBag.Status    = msg.MessageStatus;
                    ViewBag.msg       = msg.MessageInfo;
                    return(View("UserInfo"));
                }
                else
                {
                    msg = CMSService.UpdateFieldOneByOne("User", "CMSUser", "UserName='******'", "UserEmail", model.UserEmail);
                    msg.MessageStatus = "Success";
                    msg.MessageInfo   = "邮箱更改成功";
                    ViewBag.Status    = msg.MessageStatus;
                    // TODO: Add delete logic here

                    return(RedirectTo("/User/Index", msg.MessageInfo));
                }
            }
            catch
            {
                Message msg = new Message();
                msg.MessageStatus = "Error";
                msg.MessageInfo   = "操作出错了";
                ViewBag.Status    = msg.MessageStatus;
                ViewBag.msg       = msg.MessageInfo;
                return(View("UserInfo"));
            }
        }
        public ActionResult Cancel(CancelAccountViewModel viewModel)
        {
            if (!viewModel.Confirm)
            {
                var mainContract = this.DbPractice.AccountContract;

                // Get plan informations of this practice.
                // Contract text, title, description, and other things to display.
                viewModel.CurrentContract = new ConfigAccountViewModel.Contract
                {
                    PlanTitle     = mainContract.SYS_ContractType.Name,
                    UrlIdentifier = mainContract.SYS_ContractType.UrlIdentifier.Trim(),
                };

                this.ModelState.AddModelError(() => viewModel.Confirm, "A caixa de checagem de confirmação precisa ser marcada para prosseguir.");

                return(this.View(viewModel));
            }

            // Payd accounts are canceled manually.
            if (!this.DbPractice.AccountContract.SYS_ContractType.IsTrial)
            {
                this.DbPractice.AccountCancelRequest = true;

                this.db.SaveChanges();

                this.ViewBag.CancelRequested = true;

                return(this.View(viewModel));
            }

            // Sending e-mail with data.
            if (viewModel.SendDataByEmail)
            {
                foreach (var eachDoctorUser in this.DbPractice.Users.Where(u => u.DoctorId != null))
                {
                    // Rendering message bodies from partial view.
                    var emailViewModel = new UserEmailViewModel(eachDoctorUser);
                    var toAddress      = new MailAddress(eachDoctorUser.Person.Email, eachDoctorUser.Person.FullName);
                    var mailMessage    = this.CreateEmailMessagePartial("AccountDataEmail", toAddress, emailViewModel);

                    // attaching pdf
                    var pdf = ReportController.ExportPatientsPdf(null, this.db, this.DbPractice, eachDoctorUser.Doctor);

                    mailMessage.Attachments.Add(
                        new Attachment(new MemoryStream(pdf), "Prontuários.pdf", "application/pdf"));

                    // attaching xml
                    var xml = ReportController.ExportDoctorXml(this.db, this.DbPractice, eachDoctorUser.Doctor);

                    mailMessage.Attachments.Add(
                        new Attachment(
                            new MemoryStream(Encoding.UTF8.GetBytes(xml)), "Prontuários.xml", "text/xml"));

                    // sending message
                    using (mailMessage)
                    {
                        this.TrySendEmail(mailMessage);
                    }
                }
            }

            var userReason = string.IsNullOrWhiteSpace(viewModel.Reason) ? "No reason provided by user." : viewModel.Reason;

            // sending self e-mail with user reason for canceling
            using (var message = EmailHelper.CreateEmailMessage(
                       new MailAddress("*****@*****.**"),
                       string.Format("Conta cancelada pelo usuário: {0}", this.DbPractice.UrlIdentifier),
                       userReason))
            {
                this.TrySendEmail(message);
            }

            // logging off
            FormsAuthentication.SignOut();

            // disabling account
            this.DbPractice.AccountDisabled = true;
            this.DbPractice.UrlIdentifier  += " !disabled"; // change this, so that a new practice with this name can be created.
            this.db.SaveChanges();

            // redirecting user to success message (outside of the app, because the account was canceled)
            return(this.RedirectToAction("AccountCanceled", "Home", new { area = "", practice = this.DbPractice.UrlIdentifier }));
        }