Exemplo n.º 1
0
        public async Task <IActionResult> ConfirmEmail(string userId, string code)
        {
            if (userId == null || code == null)
            {
                return(View("Error"));
            }
            var applicationUser = await _identityUserManager.FindByIdAsync(userId);

            if (applicationUser == null)
            {
                return(View("Error"));
            }
            var result = await _identityUserManager.ConfirmEmailAsync(applicationUser, code);

            if (result.Succeeded)
            {
                // add role to user
                //await _userManager.AddToRoleAsync(user, "user"); //don't work on rc2???
                // Verify not exist on id
                var key = new UserKey()
                {
                    Id = applicationUser.Id
                };
                var user = _usersService.GetUser(key);
                if (user != null)
                {
                    //Verify role exist
                    var roleKey = new RoleKey();
                    roleKey.Id = "1"; //User
                    var role = _rolesService.GetRole(roleKey);
                    if (role != null)
                    {
                        user.Role = role;
                        user      = _usersService.UpdateUser(user);
                    }

                    if (user != null)
                    {
                        //Add empty user profil (for correct connect error on mobile application)
                        var userInfo = new UserInfo()
                        {
                            UserId = user.Id,
                            Unit   = TUnitType.Metric
                        };
                        _userInfosService.UpdateUserInfo(userInfo);
                    }

                    return(RedirectToAction("Index", "Home", new { area = "Site" }));
                }
            }
            return(View(result.Succeeded ? "ConfirmEmail" : "Error"));
        }
Exemplo n.º 2
0
        public IActionResult UpdateUserInfo([FromBody] UserInfo userInfo)
        {
            try
            {
                if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.UserId) ||
                    SessionUserId != userInfo.UserId)
                {
                    return(BadRequest());
                }

                userInfo = _userInfosService.UpdateUserInfo(userInfo);
                return(new OkObjectResult(userInfo));
            }
            catch (Exception exception)
            {
                return(BadRequest(new WebApiException("Error", exception)));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> ConfirmUserEmail(string id)
        {
            if (!string.IsNullOrWhiteSpace(id))
            {
                var appUser = await _identityUserManager.FindByIdAsync(id);

                if (appUser != null && !appUser.EmailConfirmed)
                {
                    appUser.EmailConfirmed = true;
                    await _identityUserManager.UpdateAsync(appUser);

                    //Add user role
                    var userKey = new UserKey()
                    {
                        Id = id
                    };
                    var user = _usersService.GetUser(userKey);
                    if (user != null)
                    {
                        //Verify role exist
                        var roleKey = new RoleKey();
                        roleKey.Id = "1"; //User
                        var role = _rolesService.GetRole(roleKey);
                        if (role != null)
                        {
                            user.Role = role;
                            user      = _usersService.UpdateUser(user);
                        }
                    }

                    //Add empty user profil (for correct connect error on mobile application)
                    var userInfoKey = new UserInfoKey()
                    {
                        UserId = id
                    };
                    var userInfo = _userInfosService.GetUserInfo(userInfoKey);
                    if (userInfo == null)
                    {
                        userInfo = new UserInfo()
                        {
                            UserId = id,
                            Unit   = TUnitType.Metric
                        };
                        _userInfosService.UpdateUserInfo(userInfo);
                    }

                    try
                    {
                        string reportData = await _reportService.CreateReportForAdminNewUserAccountCreatedAsync(user.Id);

                        await _emailSender.SendEmailAsync(appUser.Email, Translation.CONFIRM_USER_ACCOUNT, reportData);

                        await _emailSender.SendEmailAsync(appUser.Email, "Account validated",
                                                          "Your account validated by admin");
                    }
                    catch (Exception except)
                    {
                        _logger.LogError(0, except, "can't send email");
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public IActionResult Edit(UserProfilViewModel viewModel, IFormFile imageFile)
        {
            int sexId = 0, countryId = 0;

            if (ModelState.IsValid && _signInManager.IsSignedIn(User) && viewModel != null)
            {
                if (viewModel.UserId == SessionUserId)
                {
                    if (viewModel.CountryId == 0) // not specified
                    {
                        viewModel.ZipCode = string.Empty;
                    }
                    bool continute = true;
                    if (sexId < 0 && sexId > 1)
                    {
                        ModelState.AddModelError(string.Empty, string.Format("{0} {1}", Translation.INVALID_INPUT_2P, Translation.SEX));
                        viewModel.SexId = 0;
                        continute       = false;
                    }

                    if (continute && viewModel.CountryId != 0)
                    {
                        var country = _countriesService.GetCountry(new CountryKey()
                        {
                            Id = viewModel.CountryId
                        });
                        if (country == null)
                        {
                            ModelState.AddModelError(string.Empty, string.Format("{0} {1}", Translation.INVALID_INPUT_2P, Translation.COUNTRY));
                            viewModel.CountryId = 0;
                            continute           = false;
                        }
                    }

                    if (continute && !string.IsNullOrEmpty(viewModel.ZipCode))
                    { // ZipCode not Required
                        var city = _citiesService.GetCity(new CityKey()
                        {
                            CountryId = viewModel.CountryId, ZipCode = viewModel.ZipCode
                        });
                        if (city == null)
                        {
                            ModelState.AddModelError(string.Empty, string.Format("{0} {1}", Translation.INVALID_INPUT_2P, Translation.ZIP_CODE));
                            continute = false;
                        }
                    }

                    sexId     = viewModel.SexId;
                    countryId = viewModel.CountryId;

                    if (continute)
                    {
                        var userInfo = new UserInfo()
                        {
                            UserId       = viewModel.UserId,
                            Unit         = (TUnitType)viewModel.Unit,
                            Height       = viewModel.Height,
                            Weight       = viewModel.Weight,
                            ZipCode      = viewModel.ZipCode,
                            CountryId    = viewModel.CountryId,
                            Sex          = (TSexType)viewModel.SexId,
                            TimeZoneName = viewModel.TimeZoneName,
                        };

                        userInfo = _userInfosService.UpdateUserInfo(userInfo);

                        if (!string.IsNullOrWhiteSpace(userInfo.UserId) && ImageUtils.CheckUploadedImageIsCorrect(imageFile))
                        {
                            string ext = ImageUtils.GetImageExtension(imageFile);
                            if (string.IsNullOrWhiteSpace(ext))
                            {
                                return(BadRequest());
                            }
                            ImageUtils.SaveImage(imageFile, Path.Combine(_env.WebRootPath, "images", "userprofil"), userInfo.UserId + ext);
                        }

                        return(RedirectToAction("Index"));
                    }
                }
            }

            ViewBag.Sex       = ControllerUtils.CreateSelectSexItemList(sexId);
            ViewBag.Countries = ControllerUtils.CreateSelectCountryItemList(_countriesService.FindCountries(), countryId);
            ViewBag.Units     = ControllerUtils.CreateSelectUnitItemList(viewModel.Unit);
            ViewBag.TimeZones = ControllerUtils.CreateSelectTimeZoneItemList(viewModel.TimeZoneName);
            return(View(viewModel));
        }