Esempio n. 1
0
        public async Task <IActionResult> Edit(ApplicationUserVm userUpdated)
        {
            if (userUpdated.CarrierId != null && CheckIfCarrierExistsInAnotherUser(userUpdated.Id, userUpdated.CarrierId))
            {
                ModelState.AddModelError("CarrierId", "Среди пользователей уже есть такой перевозчик");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var user = await _carrierService.GetUserById(userUpdated.Id);

                    user.Inn       = userUpdated.Inn;
                    user.Kpp       = userUpdated.Kpp;
                    user.Fio       = userUpdated.Fio;
                    user.CarrierId = userUpdated.CarrierId;

                    //      await AddClaim(userUpdated.Id, "CarrierId", userUpdated.CarrierId);

                    await _dbContext.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException e)
                {
                    _logger.LogError(e.Message);
                    throw;
                }
                return(RedirectToAction(nameof(Index)));
            }


            return(View(await GetModel(userUpdated.Id)));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(ApplicationUserVm userVm)
        {
            if (!ModelState.IsValid)
            {
                return(View(userVm));
            }
            ApplicationUser user = new ApplicationUser();

            user.UserName           = userVm.UserName;
            user.NormalizedUserName = user.UserName.ToUpper();
            user.Email           = userVm.Email;
            user.NormalizedEmail = user.Email.ToUpper();
            PasswordHasher <ApplicationUser> hasher = new PasswordHasher <ApplicationUser>();

            user.PasswordHash         = hasher.HashPassword(user, userVm.NewPassword);
            user.EmailConfirmed       = userVm.EmailConfirmed;
            user.LockoutEnabled       = userVm.LockoutEnabled;
            user.LockoutEnd           = userVm.LockoutEnd;
            user.PhoneNumber          = userVm.PhoneNumber;
            user.PhoneNumberConfirmed = userVm.PhoneNumberConfirmed;
            user.TwoFactorEnabled     = userVm.TwoFactorEnabled;
            user.Currency             = userVm.Currency;
            await _userManager.CreateAsync(user);

            return(RedirectToAction("Details", new { id = user.Id }));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(string id, ApplicationUserVm userVm)
        {
            if (id != userVm.Id)
            {
                return(NotFound());
            }
            if (!ModelState.IsValid)
            {
                return(View(userVm));
            }
            ApplicationUser user = await _userManager.FindByIdAsync(id);

            user.UserName           = userVm.UserName;
            user.NormalizedUserName = user.UserName.ToUpper();
            user.Email           = userVm.Email;
            user.NormalizedEmail = user.Email.ToUpper();
            if (!String.IsNullOrEmpty(userVm.NewPassword))
            {
                PasswordHasher <ApplicationUser> hasher = new PasswordHasher <ApplicationUser>();
                user.PasswordHash = hasher.HashPassword(user, userVm.NewPassword);
            }
            user.EmailConfirmed       = userVm.EmailConfirmed;
            user.LockoutEnabled       = userVm.LockoutEnabled;
            user.LockoutEnd           = userVm.LockoutEnd;
            user.PhoneNumber          = userVm.PhoneNumber;
            user.PhoneNumberConfirmed = userVm.PhoneNumberConfirmed;
            user.TwoFactorEnabled     = userVm.TwoFactorEnabled;
            user.Currency             = userVm.Currency;
            await _userManager.UpdateAsync(user);

            return(RedirectToAction("Details", new { id = user.Id }));
        }
Esempio n. 4
0
 public ActionResult Index(ApplicationUserVm model)
 {
     if ((model.Email == "*****@*****.**") && (model.Password == "123"))
     {
         FormsAuthentication.SetAuthCookie("*****@*****.**", true);
         return(RedirectToAction("Index", "Home"));
     }
     return(View(model));
 }
Esempio n. 5
0
        public static async Task <string> GenerateJwt(ClaimsIdentity identity, IJwtFactory jwtFactory, string userName, JwtIssuerOptions jwtOptions, JsonSerializerSettings serializerSettings, ApplicationUserVm applicationUser)
        {
            var response = new
            {
                id         = identity.Claims.Single(c => c.Type == "id").Value,
                auth_token = await jwtFactory.GenerateEncodedToken(userName, identity),
                expires_in = (int)jwtOptions.ValidFor.TotalSeconds,
                user       = applicationUser
            };

            return(JsonConvert.SerializeObject(response, serializerSettings));
        }