Ejemplo n.º 1
0
        public async Task <IActionResult> UserRegister(UserForRegistration userForRegister)
        {
            var user = new User()
            {
                Username    = userForRegister.Username,
                Fullname    = userForRegister.Fullname,
                IsDeveloper = userForRegister.IsDeveloper,
            };

            user = await _userRepository.RegisterUser(user, userForRegister.Password);

            if (user == null)
            {
                ModelState.AddModelError("Username", "User Exists");

                return(BadRequest(ModelState));
            }

            await _context.SaveChangesAsync();

            return(await UserLogin(new UserForLogin()
            {
                Username = userForRegister.Username, Password = userForRegister.Password
            }, ""));
        }
Ejemplo n.º 2
0
        public User Register(UserForRegistration userForRegistration)
        {
            if (userForRegistration == null)
            {
                return(null);
            }
            if (userForRegistration.Password == null || userAPI == null)
            {
                return(null);
            }
            var sha256 = new SHA256CryptoServiceProvider();

            var hashedPassword = ConvertByteArrayToString(
                sha256.ComputeHash(ConvertStringToByteArray(userForRegistration.Password)));

            sha256.Dispose();
            var user = userAPI.GetUserFromDatabase(userForRegistration.Name);

            if (user != null)
            {
                return(null);
            }
            user           = new User();
            user.Name      = userForRegistration.Name;
            user.Password  = hashedPassword;
            user.FirstName = userForRegistration.FirstName;
            user.LastName  = userForRegistration.LastName;

            userAPI.AddUser(user);

            user.Password = null;
            return(user);
        }
        public void CreateUser(UserForRegistration user, string password)
        {
            List <User> users = GetUsers();
            User        us    = user.Convert();

            us.Password = password;
            users.Add(us);
            SaveUser(users);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Register(UserForRegistration user)
        {
            //validate request
            user.Username = user.Username.ToLower();
            if (await _repo.UserExists(user.Username))
            {
                return(BadRequest("User already exists"));
            }
            var createuser = new User();

            createuser.UserName = user.Username;
            var createduser = await _repo.Register(createuser, user.Password);

            return(StatusCode(201));
        }
Ejemplo n.º 5
0
        public static User Convert(this UserForRegistration user)
        {
            if (user == null)
            {
                return(null);
            }

            return(new User
            {
                EmailAddress = user.EmailAddress,
                FirstName = user.FirstName,
                Image = null,
                LastName = user.LastName
            });
        }
Ejemplo n.º 6
0
        public void CreateUser(UserForRegistration user, string password)
        {
            DataManagement api = new DataManagement(URL_BASE);

            Dictionary <string, object> userData = new Dictionary <string, object>
            {
                { "email", user.EmailAddress },
                { "lastname", user.LastName },
                { "firstname", user.FirstName },
                { "password", password }
            };

            var content = new StringContent(JsonConvert.SerializeObject(userData), Encoding.UTF8, "application/json");

            api.SendPost("/signup", content);
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Register(UserForRegistration userForRegistration)
        {
            var userToCreate = _mapper.Map <User>(userForRegistration);

            var result = await _userManager.CreateAsync(userToCreate, userForRegistration.Password);

            var userToReturn = _mapper.Map <UserForDetailDto>(userToCreate);

            if (result.Succeeded)
            {
                return(CreatedAtRoute("GetUser",
                                      new { controller = "Users", id = userToCreate.Id },
                                      userToReturn));
            }

            return(BadRequest(result.Errors));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Register(UserForRegistration userForRegistration)
        {
            userForRegistration.Username = userForRegistration.Username.ToLower();
            if (await _repo.UserExists(userForRegistration.Username))
            {
                return(BadRequest("User already exists"));
            }

            var userToCreate = new User
            {
                UserName = userForRegistration.Username
            };

            await _repo.Register(userToCreate, userForRegistration.Password);

            return(StatusCode(201));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Register(UserForRegistration userForReg)
        {
            var userName = userForReg.Username.ToLower();

            if (await _repo.UserExists(userName))
            {
                return(BadRequest("Username already exist"));
            }

            var user = new User
            {
                Username = userName
            };

            var createdUser = await _repo.Register(user, userForReg.Password);

            return(Ok(createdUser));
        }
Ejemplo n.º 10
0
        public IActionResult Register(UserForRegistration userParam)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new { message = "User already exists" }));
            }
            if (userParam == null)
            {
                return(BadRequest());
            }
            var user = userService.Register(userParam);

            if (user == null)
            {
                return(BadRequest(new { message = "User already exists" }));
            }
            return(Ok(user));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> RegisterUser([FromBody] UserForRegistration userDTO)
        {
            var newUser = new User
            {
                FirstName   = userDTO.FirstName,
                LastName    = userDTO.LastName,
                UserName    = userDTO.UserName,
                Email       = userDTO.Email,
                PhoneNumber = userDTO.PhoneNumber
            };

            var result = await _userManager.CreateAsync(newUser, userDTO.Password);

            if (!result.Succeeded)
            {
                foreach (var error in result.Errors)
                {
                    ModelState.TryAddModelError(error.Code, error.Description);
                }
                return(BadRequest(ModelState));
            }

            //Check if roles exists in Db
            var roleResult = new List <string>();

            foreach (var role in userDTO.Roles)
            {
                if (!await _roleManager.RoleExistsAsync(role))
                {
                    roleResult.Add($"Role \"{role}\" does not exist.");
                }
            }

            if (roleResult.Count() > 0)
            {
                return(BadRequest(roleResult));
            }

            await _userManager.AddToRolesAsync(newUser, userDTO.Roles);

            return(Ok());
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Register([FromBody] UserForRegistration userForRegistration)
        {
            // Business Validation
            if (await _repo.UserExists(userForRegistration.Username))
            {
                ModelState.AddModelError("Username", "Username already in use.");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userToCreate = _mapper.Map <User>(userForRegistration);
            var createdUser  = await _repo.Register(userToCreate, userForRegistration.Password);

            var userToReturn = _mapper.Map <UserForDetail>(createdUser);

            return(CreatedAtRoute("GetUser", new { id = userToReturn.Id }, userToReturn));
        }
 public void CreateUser(UserForRegistration user, string password)
 {
     this._wsWodBoard.CreateUser(user, password);
 }