Ejemplo n.º 1
0
        public UserInfo CreateUser(UserInfo user, string password)
        {
            _users = _userProvider.GetAllUsers();
            // validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }

            if (_users.Any(x => x.UserName == user.UserName))
            {
                throw new AppException("Username \"" + user.UserName + "\" is already taken");
            }

            if (_users.Any(x => x.Email == user.Email))
            {
                throw new AppException("Email \"" + user.Email + "\" is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            if (string.IsNullOrWhiteSpace(user.Role))
            {
                user.Role = Role.User;
            }
            _userProvider.AddUser(user);
            return(user);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Register a new user
        /// </summary>
        /// <param name="user">The credentials to register</param>
        /// <returns>Registered user</returns>
        public Contracts.User RegisterUser(Login user)
        {
            ValidateInput(user);

            user.Password = BCrypt.Net.BCrypt.HashPassword(user.Password);

            _userProvider.AddUser(user);

            return(user.ToContract());
        }
 public IActionResult Register(UserViewModel user)
 {
     if (ModelState.IsValid)
     {
         var role = roleProvider.GetRole("Viewer");
         user.Role = role;
         if (userProvider.AddUser(user) != 0)
         {
             return(View("SuccessfulRegistration"));
         }
     }
     return(View(user));
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            EndpointAddress address = new EndpointAddress("http://localhost:8081/User");
            WSHttpBinding   binding = new WSHttpBinding();

            ChannelFactory <IUserProvider> factory = new ChannelFactory <IUserProvider>(binding, address);

            IUserProvider channel = factory.CreateChannel();

            string result = channel.AddUser(new Model.UserDTO {
                Name = "测试"
            });

            Console.WriteLine(result);
            Console.ReadLine();
        }
Ejemplo n.º 5
0
        public async Task <User> Authenticate(string username)
        {
            if (string.IsNullOrEmpty(username))
            {
                throw new ArgumentNullException();
            }

            var users = await _userProvider.GetUsers();

            var res = users.FirstOrDefault(user => user.Username == username);

            if (res != null)
            {
                return(res);
            }

            return(await _userProvider.AddUser(new User { Username = username }));
        }
Ejemplo n.º 6
0
        public ActionResult AddUser(User user)
        {
            if (ModelState.IsValid)
            {
                bool result = userProvider.AddUser(user);
                if (!result)
                {
                    log.Error("Controller: User, Action: AddUser Don't add user");
                }

                return(RedirectToAction("UsersAll"));
            }
            else
            {
                SelectList roles = new SelectList(userProvider.GetRolesAll(), "RoleId", "Name");
                if (roles == null)
                {
                    log.Error("Controller: User, Action: AddUser Don't GetRolesAll");
                    return(RedirectToAction("InfoError", "Error"));
                }
                ViewBag.Roles = roles;
                return(View());
            }
        }
 public IActionResult  AddUser([FromBody] User user)
 {
     userProvider.AddUser(user);
     return(Ok(user));
 }