Ejemplo n.º 1
0
        private async Task <ActionResult> AddNewUserToOrganizationAsync(CustomerBasicInfo organization, AddUserToOrganizationFormViewModel viewModel)
        {
            var user = await _accountRepo.CreateUserAsync(viewModel.FirstName, viewModel.LastName, viewModel.Telephone,
                                                          viewModel.Mobile, viewModel.Email, string.Empty, string.Empty, string.Empty);

            if (user == null)
            {
                throw new ApplicationException("CreateNewFailed");
            }

            var roles = viewModel.Roles.Split(',');
            await _orgUserRepo.AddUserToOrganizationAsync(user, organization, roles);

            var startPage   = _contentRepo.Get <StartPage>(ContentReference.StartPage);
            var settingPage = _contentRepo.Get <SettingsPage>(startPage.SettingsPage);

            var guid = await _securityRepository.GeneratePasswordGuidAsync(user.UserName);

            var resetPasswordToken = _tokenGenerator.Encrypt(new ResetPasswordConfirmationData
            {
                GuidString = guid,
                UserName   = viewModel.Email
            });

            //fire and forget email
            //var host = Request.Url?.Host + (Request?.Url?.IsDefaultPort == true ? "" : ":" + Request?.Url?.Port);
            var link = $"{ConfigurationManager.AppSettings["publicSitePrefix"]}/p/resetpassword?payload={resetPasswordToken}";

            await SendEmailToNewUserAsync(viewModel.Email, viewModel.Roles, link, organization.CustomerName);

            TempData["reference"] = "NewUserAdded";
            return(RedirectToAction("Index", new { node = settingPage.HandleOrganizationUserPage }));
        }
Ejemplo n.º 2
0
        public void UpdateInternalCustomerNumber(HttpContextBase httpContext, CustomerBasicInfo customer)
        {
            if (httpContext?.Response?.Cookies == null || customer == null)
            {
                return;
            }
            var cookie = _tokenGenerator.Encrypt(customer);

            httpContext.SetCookie(Cookies.InternalActiveCustomer, cookie, true);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> AddNewUserToOrganizationAsync(AddUserToOrganizationFormViewModel viewModel, string customerNumber)
        {
            var existingUser = await UserManager.QuerySiteUserAsync(viewModel.Email);

            if (existingUser != null)
            {
                return(new HttpStatusCodeResult(400));
            }

            var user = await _accountRepo.CreateUserAsync(viewModel.FirstName, viewModel.LastName, viewModel.Telephone,
                                                          viewModel.Mobile, viewModel.Email, string.Empty, string.Empty, string.Empty);

            if (user == null)
            {
                throw new ApplicationException("CreateNewFailed");
            }

            var customer = await _customerSupportRepo.GetCustomerByNumberAsync(customerNumber);

            var roles = viewModel.Roles.Split(',');
            await _orgUserRepo.AddUserToOrganizationAsync(user, new CustomerBasicInfo
            {
                CustomerName = customer.CustomerName,
                CustomerNo   = customerNumber
            }, roles);

            var guid = await _securityRepository.GeneratePasswordGuidAsync(user.UserName);

            var resetPasswordToken = _tokenGenerator.Encrypt(new ResetPasswordConfirmationData
            {
                GuidString = guid,
                UserName   = viewModel.Email
            });

            //fire and forget email
            //var host = Request.Url?.Host + (Request?.Url?.IsDefaultPort == true ? "" : ":" + Request?.Url?.Port);
            var link = $"{ConfigurationManager.AppSettings["publicSitePrefix"]}/p/resetpassword?payload={resetPasswordToken}";

            await SendEmailToNewUserAsync(viewModel.Email, viewModel.Roles, link, customer.CustomerName);

            return(Json(true));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> SubmitForgotPasswordEmail(LostPasswordSubmissionViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(new HttpStatusCodeResult(400, "InvalidEmail"));
            }

            ViewData["email"] = viewModel.Email;

            var userName = _securityRepo.GetUserNameByEmail(viewModel.Email);

            if (string.IsNullOrWhiteSpace(userName))
            {
                return(PageView("Email sent"));
            }

            var guid = await _securityRepo.GeneratePasswordGuidAsync(userName);

            var user = await _userManager.QuerySiteUserAsync(userName);

            var resetPasswordToken = _tokenGenerator.Encrypt(new ResetPasswordConfirmationData
            {
                GuidString = guid,
                UserName   = userName
            });

            ViewData["link"]     = $"{ConfigurationManager.AppSettings["publicSitePrefix"]}/p/resetpassword?payload={resetPasswordToken}";
            ViewData["payload"]  = resetPasswordToken;
            ViewData["userName"] = user.Name;

            var emailBody = this.RenderPartialViewToString("~/Views/MyProfile/ResetPasswordEmailTemplate.cshtml", ViewData);
            await _emailService.SendMailAsync(Email.LantmannenFromAddress, new[] { viewModel.Email },
                                              new string[0], "Återställ lösenord i LM" + "\xB2", emailBody, _ticket)
            .ConfigureAwait(false);

            return(PageView("Email sent"));
        }