Example #1
0
        public async Task <IActionResult> ChangePhoneNumber(ChangePhoneNumberModel model)
        {
            var member = await HttpContext.GetMemberAsync();

            if (HttpMethods.IsGet(Request.Method))
            {
                ModelState.Clear();
            }
            else if (HttpMethods.IsPost(Request.Method))
            {
                if (ModelState.IsValid)
                {
                    var result = await _userService.SetPhoneNumberAsync(member, model.NewPhoneNumber);

                    if (result.Succeeded)
                    {
                        TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"Phone number was set to {_appSettings.FormatPhoneNumber(model.NewPhoneNumber)}.");
                    }
                    else
                    {
                        ModelState.AddIdentityResult(result);
                    }
                }
            }

            return(PartialView(model));
        }
Example #2
0
        public async Task <IActionResult> ChangePassword(ChangePasswordModel model)
        {
            var member = await HttpContext.GetMemberAsync();

            if (HttpMethods.IsGet(Request.Method))
            {
                ModelState.Clear();
            }
            else if (HttpMethods.IsPost(Request.Method))
            {
                if (ModelState.IsValid)
                {
                    var result = await _userService.ChangePasswordAsync(member, model.CurrentPassword, model.NewPassword);

                    if (result.Succeeded)
                    {
                        TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"Password was changed.");
                    }
                    else
                    {
                        ModelState.AddIdentityResult(result);
                    }
                }
            }

            return(PartialView(model));
        }
Example #3
0
        public async Task <IActionResult> EditPayment(PaymentEditModel model)
        {
            var user = await HttpContext.GetMemberAsync();

            var issuers = await _paymentProcessor.GetIssuersAsync();

            model.MobileIssuerOptions.AddRange(SelectListHelper.GetSelectList(elements: issuers.Where(x => x.Mode == PaymentMode.Mobile), x => new SelectListItem <PaymentIssuer>(x.Name, x.Code)));
            model.BankIssuerOptions.AddRange(SelectListHelper.GetSelectList(elements: issuers.Where(x => x.Mode == PaymentMode.Bank), x => new SelectListItem <PaymentIssuer>(x.Name, x.Code)));

            if (HttpMethods.IsGet(Request.Method))
            {
                ModelState.Clear();

                if (model.Mode == PaymentMode.Mobile)
                {
                    model.MobileIssuer = user.MobileIssuer;
                    model.MobileNumber = user.MobileNumber;
                }
                else if (model.Mode == PaymentMode.Bank)
                {
                    model.BankIssuer = user.BankIssuer;
                    model.BankNumber = user.BankNumber;
                }
            }
            else if (HttpMethods.IsPost(Request.Method))
            {
                if (ModelState.IsValid)
                {
                    if (model.Mode == PaymentMode.Mobile)
                    {
                        user.MobileIssuer = model.MobileIssuer;
                        user.MobileNumber = model.MobileNumber;
                    }
                    else if (model.Mode == PaymentMode.Bank)
                    {
                        user.BankIssuer = model.BankIssuer;
                        user.BankNumber = model.BankNumber;
                    }

                    var result = await _userService.UpdateAsync(user);

                    if (result.Succeeded)
                    {
                        TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"Payment details was updated.");
                    }
                    else
                    {
                        ModelState.AddIdentityResult(result);
                    }
                }
            }

            return(PartialView(nameof(EditPayment), model));
        }
Example #4
0
        public async Task <IActionResult> EditStore(StoreEditModel model)
        {
            if (ModelState.IsValid)
            {
                var seller = await HttpContext.GetMemberAsync();

                var firstStoreSetup = false;

                await _appService.PrepareStoreAsync(seller, model);

                if (!seller.StoreSetup)
                {
                    seller.StoreSetup = true;
                    firstStoreSetup   = true;
                }

                var result = await _userService.CheckStoreSlugAsync(seller);

                result = result.Succeeded ? await _userService.UpdateAsync(seller) : result;

                if (result.Succeeded)
                {
                    if (firstStoreSetup)
                    {
                        await _messageService.SendEmailAsync(
                            messageRole : MessageRole.Notification,
                            messageType : MessageType.CompanyWelcome,
                            messageDisplay : "Neimart",
                            email : seller.Email,
                            subject : "You have just started a new business",
                            model : new ValueTuple <User, object>(seller, null));
                    }

                    await SaveStoreLogoAsync(seller, model);
                    await SaveStoreDocumentAsync(seller, model);

                    TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"Store was updated.");
                }
                else
                {
                    ModelState.AddIdentityResult(result);
                }
            }

            return(RedirectToAction());
        }
Example #5
0
        public async Task <IActionResult> ResetPassword(ResetPasswordModel model, string token, string email, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (!string.IsNullOrWhiteSpace(token) &&
                    !string.IsNullOrWhiteSpace(email))
                {
                    var member = await _userService.FindByEmailAsync(email);

                    if (member != null)
                    {
                        var result = await _userService.ResetPasswordAsync(member, token, model.Password);

                        if (result.Succeeded)
                        {
                            TempData.AddAlert(AlertMode.Notify, AlertType.Success, "Password was reseted.");

                            return(RedirectToAction(nameof(Signin), new { email, returnUrl }));
                        }
                        else
                        {
                            ModelState.AddIdentityResult(result);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, $"No user registered with {email} email.");
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Sorry, Something went wrong. Please try requesting the password reset link again.");
                }
            }

            return(RedirectToAction(nameof(ResetPassword), new { token, email, returnUrl }));
        }
Example #6
0
        public async Task <IActionResult> EditProfile(ProfileEditModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var member = await HttpContext.GetMemberAsync();

                await _appService.PrepareProfileAsync(member, model);

                var result = await _userService.UpdateAsync(member);

                if (result.Succeeded)
                {
                    await SaveProfileImageAsync(member, model);

                    TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"Profile was updated.");
                }
                else
                {
                    ModelState.AddIdentityResult(result);
                }
            }

            return(RedirectToAction(nameof(EditProfile), new { returnUrl }));
        }
Example #7
0
        public async Task <IActionResult> Signup(SignUpModel model, string storeName, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var member = new User
                {
                    Email       = model.Email,
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    PhoneNumber = model.PhoneNumber,
                };

                await _userService.GenerateUserCodeAsync(member);

                await _userService.GenerateUserNameAsync(member);
                await PrepareStoreAsync(member);

                var result = await _userService.CreateAsync(member, model.Password);

                if (result.Succeeded)
                {
                    result = await _userService.AddToRolesAsync(member, new[] { RoleNames.Seller, RoleNames.Customer });

                    if (!result.Succeeded)
                    {
                        throw new InvalidOperationException(result.Errors.Select(x => x.Description).Humanize());
                    }

                    if (!_signInService.Options.SignIn.RequireConfirmedEmail &&
                        !_signInService.Options.SignIn.RequireConfirmedPhoneNumber)
                    {
                        await _signInService.SignInAsync(member, isPersistent : false);

                        return(LocalRedirect(returnUrl ?? Url.Action("Index", "Home", new { area = "Portal" })));
                    }
                    else
                    {
                        var token = await _userService.GenerateEmailConfirmationTokenAsync(member);

                        var link = Url.Action(nameof(VerifyEmail), "Account", new { userId = member.Id, token, returnUrl }, protocol: Request.Scheme);

                        await _messageService.SendEmailAsync(
                            messageRole : MessageRole.Notification,
                            messageType : MessageType.VerifyEmail,
                            messageDisplay : "Neimart Support",
                            email : member.Email,
                            model : new ValueTuple <User, string>(member, link));

                        TempData.AddAlert(AlertMode.Alert, AlertType.Success, $"Congratulations! Your account has been created successfully. We'll send you an email within a few minutes with instructions to verify your email address. If the email does not arrive soon, check your spam, junk, and bulk mail folders.", title: "Email Verification Required");

                        return(RedirectToAction(nameof(Signin), new { returnUrl }));
                    }
                }
                else
                {
                    ModelState.AddIdentityResult(result);
                }
            }

            return(RedirectToAction(nameof(Signup), new { storeName, returnUrl }));
        }