Beispiel #1
0
        public async Task <IActionResult> Register(RegistrationUserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = new User()
            {
                UserName = model.UserName
            };
            var regResult = await _userManager.CreateAsync(user, model.Password);

            if (regResult.Succeeded)
            {
                await _userManager.AddToRoleAsync(user, DomainEntities.Entities.User.UserRole);

                await _signInManager.SignInAsync(user, false);

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                foreach (var regResultError in regResult.Errors)
                {
                    ModelState.AddModelError("", regResultError.Description);
                }
                return(View(model));
            }
        }
        public async Task Registration(RegistrationUserViewModel model)
        {
            if (model != null)
            {
                Wall wall = new Wall {
                    CreationDate = DateTime.UtcNow
                };
                _repositoryService.GetRepository <Wall>().Add(wall);
                var content = new Content {
                    CreationDate = DateTime.UtcNow
                };
                _repositoryService.GetRepository <Content>().Add(content);
                User user = new User {
                    Email = model.Email, UserName = model.Login, WallId = wall.Id, ContentId = content.Id, NickName = model.NickName, Gender = model.Gender
                };
                // добавляем пользователя
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    // установка куки
                    //await _signInManager.SignInAsync(user, false);//не будет работать нужны токены
                }
                else
                {
                    throw new Exception();
                }
            }
        }
Beispiel #3
0
        public ActionResult RegistrationUser()
        {
            var viewModel = new RegistrationUserViewModel
            {
                CurrentCountries = this._countryService.GetCountries()
            };

            return(this.View(viewModel));
        }
Beispiel #4
0
 public IActionResult Registration(RegistrationUserViewModel viewModel)
 {
     try
     {
         var k = _userService.Registration(viewModel);
         return(Ok("Success"));
     }
     catch (Exception ex)
     {
         return(Ok("Failed"));
     }
 }
Beispiel #5
0
        public async Task <ActionResult> Register(RegistrationUserViewModel user)
        {
            var validator = _validatorFactory.GetValidator <RegistrationUserViewModel>();
            var result    = validator.Validate(user);

            if (result.IsValid)
            {
                var res = await _authService.RegisterUserAsync(Mapper.Map <UserDto>(user));

                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                return(View(user));
            }
        }
Beispiel #6
0
        public async Task <ActionResult> Registration([FromBody] RegistrationUserViewModel model)
        {
            try
            {
                var result = await _userService.Registration(model, "User");

                Response.Headers.Add("UserId", result[0]);
                Response.Headers.Add("Role", result[1]);

                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest("Error"));
            }
        }
Beispiel #7
0
        public async Task <string[]> Registration(RegistrationUserViewModel model, string role)
        {
            if (_applicationContext.Users.Any(w => w.UserName == model.UserName))
            {
                throw new Exception();
            }
            if (_applicationContext.Users.Any(w => w.Email == model.Email))
            {
                throw new Exception();
            }
            var user = new User
            {
                Id       = Guid.NewGuid().ToString(),
                UserName = model.UserName,
                Password = model.Password,
                Email    = model.Email,

                FirstName   = model.FirstName,
                LastName    = model.LastName,
                PhoneNumber = model.PhoneNumber,

                State       = model.State,
                City        = model.City,
                Address     = model.Address,
                HouseNumber = model.HouseNumber,

                DateTimeCreate = DateTime.Now,
                Role           = await _applicationContext.Roles.FirstOrDefaultAsync(w => w.Name == role)
            };
            await _applicationContext.Users.AddAsync(user);

            await _applicationContext.SaveChangesAsync();

            var basket = new Basket
            {
                Id     = Guid.NewGuid().ToString(),
                UserId = user.Id
            };
            await _applicationContext.Baskets.AddAsync(basket);

            await _applicationContext.SaveChangesAsync();

            return(new[] { user.Id, role });
        }
Beispiel #8
0
 private async Task AdminCreate()
 {
     using (_applicationContext)
     {
         var user = new RegistrationUserViewModel
         {
             UserName    = "******",
             Email       = "Admin",
             FirstName   = "Admin",
             Password    = "******",
             State       = "Admin",
             City        = "Admin",
             HouseNumber = "6",
             LastName    = "Admin",
             Address     = "Admin",
             PhoneNumber = "+666(66)666-66-66"
         };
         await _userService.Registration(user, "Admin");
     }
 }
Beispiel #9
0
 private async Task UserCreate()
 {
     using (_applicationContext)
     {
         for (int i = 1; i <= 20; i++)
         {
             var user = new RegistrationUserViewModel
             {
                 UserName    = $"SomeUserName{i}",
                 Email       = $"SomeEmail{i}",
                 FirstName   = $"SomeFirstName{i}",
                 Password    = $"SomePassword{i}",
                 State       = "Belarus",
                 City        = "Minsk",
                 HouseNumber = $"{i}",
                 LastName    = $"SomeLastName{i}",
                 Address     = "SomeAddress",
                 PhoneNumber = "+375(29)123-45-67"
             };
             await _userService.Registration(user, "User");
         }
     }
 }
Beispiel #10
0
        public ActionResult Register(RegistrationUserViewModel registrationUser)
        {
            if (ModelState.IsValid)
            {
                User user = new User();

                user.Name    = registrationUser.Name;
                user.Surname = registrationUser.Surname;
                user.Email   = registrationUser.Email;
                user.Role    = "Normal";

                PasswordHasher passHash = new PasswordHasher();
                user.PasswordHash = passHash.HashPassword(registrationUser.ConfirmPassword);

                repository.AddUser(user);

                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                return(View(registrationUser));
            }
        }
Beispiel #11
0
        public ActionResult RegistrationUser(RegistrationUserViewModel user)
        {
            var country = this._countryService.GetCountry(user.CurrentCountryId);

            user.CurrentUser.Address.Country = country;
            string message;
            bool   isExist = this._userService.IsExist(user.CurrentUser.Login, user.CurrentUser.Password, out message);

            if (isExist)
            {
                ModelState.AddModelError(string.Empty, message);
            }

            if (ModelState.IsValid)
            {
                this._userService.AddUser(user.CurrentUser);
                this._userService.SaveUser();
                ViewBag.SavedSuccessfullyMessage = true;
                if (Request.IsAuthenticated && User.IsInRole("Admin"))
                {
                    return(this.Redirect("Users"));
                }
                else
                {
                    this.TempData["SavedSuccessfully"] = true;
                    return(this.RedirectToAction("LogIn", "Account"));
                }
            }

            ViewBag.ErrorSavingMessage = true;

            return(this.View(new RegistrationUserViewModel
            {
                CurrentCountries = this._countryService.GetCountries()
            }));
        }
Beispiel #12
0
        public ActionResult Register()
        {
            RegistrationUserViewModel registrationUser = new RegistrationUserViewModel();

            return(View(registrationUser));
        }