Esempio n. 1
0
        private async void btnCreate_Click(object sender, EventArgs e)
        {
            if (IsValidControls())
            {
                try
                {
                    //Save user to the database
                    UserModel oUser = GetUser();
                    //check if the user name already exist.
                    if (await user.SelectUser(oUser.Name) == null)
                    {
                        await user.CreateUser(oUser);
                    }

                    else
                    {
                        MessageBox.Show("User name already exist. Choose a different user name.", "User name exist", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    if (Logger.FullName != null)
                    {
                        Logger.WriteToFile(Logger.FullName, $"Created a new user: {oUser.Name}");
                    }
                    MessageBox.Show("A new user has been successfully created", "Create User", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    await ResetControls();

                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Sorry an error occured. \n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Esempio n. 2
0
        public void CreateUser(User user, string password)
        {
            user.salt = helper.CreateSalt(8);

            user.password = helper.HashString(password, user.salt);



            _userdata.CreateUser(user);
        }
Esempio n. 3
0
        public async Task <User> CreateUser(User user, CancellationToken cancellationToken)
        {
            var userEntity = _iMapper.Map <UserEntity>(user);

            await _iUserData.CreateUser(userEntity, cancellationToken);

            var result = _iMapper.Map <User>(userEntity);

            return(result);
        }
Esempio n. 4
0
        public async Task <IActionResult> Register(UserRegistationModel userRegistationModel)
        {
            if (ModelState.IsValid)
            {
                var existingUser = await _userManager.FindByEmailAsync(userRegistationModel.EmailAddress);

                if (existingUser is null)
                {
                    IdentityUser identityUser = new()
                    {
                        Email          = userRegistationModel.EmailAddress,
                        EmailConfirmed = true,
                        UserName       = userRegistationModel.EmailAddress
                    };
                    IdentityResult result = await _userManager.CreateAsync(identityUser, userRegistationModel.Password);

                    if (result.Succeeded)
                    {
                        existingUser = await _userManager.FindByEmailAsync(userRegistationModel.EmailAddress);

                        UserModel u = new()
                        {
                            Id           = existingUser.Id,
                            FirstName    = userRegistationModel.FirstName,
                            LastName     = userRegistationModel.LastName,
                            EmailAddress = userRegistationModel.EmailAddress
                        };
                        _userData.CreateUser(u);
                        return(Ok());
                    }
                }
            }
            return(BadRequest());
        }
    }
}
Esempio n. 5
0
        public bool CreateUser(UserDTO user)
        {
            User userDb = Mapper.Map <User>(user);

            return(_userData.CreateUser(userDb));
        }