예제 #1
0
        public async Task <User> UpdateUser(int userId, UserBody userBody)
        {
            // create user
            User updatedUser = new User
            {
                Id          = userId,
                Name        = userBody.Name,
                Email       = userBody.Email,
                Dateofbirth = userBody.Dateofbirth,
                Gender      = userBody.Gender,
                Type        = userBody.Type
            };

            if (userBody.Password != null)
            {
                // create salt
                byte[] salt = EncryptionUtil.CreateSalt();

                updatedUser.Password = EncryptionUtil.Hash(userBody.Password, salt);
                updatedUser.Salt     = salt;
            }

            // save to database
            updatedUser = await userRepository.UpdateAsync(updatedUser);

            return(updatedUser);
        }
예제 #2
0
 public static User CreateNormalUser(int id = 1, string email = "*****@*****.**")
 {
     byte[] salt = EncryptionUtil.CreateSalt();
     return(new User
     {
         Id = id,
         Name = "Pete",
         Email = email,
         Password = EncryptionUtil.Hash("pete", salt),
         Salt = salt,
         Dateofbirth = new DateTime(2000, 1, 1),
         Gender = UserGender.Male,
         Type = UserType.User
     });
 }
예제 #3
0
 public static User CreateUserByType(UserType userType)
 {
     byte[] salt = EncryptionUtil.CreateSalt();
     return(new User
     {
         Id = 4,
         Name = "User",
         Email = "*****@*****.**",
         Password = EncryptionUtil.Hash("user", salt),
         Salt = salt,
         Dateofbirth = new DateTime(2000, 1, 1),
         Gender = UserGender.Male,
         Type = userType
     });
 }
예제 #4
0
 public static User CreateAdminUser(int id = 3)
 {
     byte[] salt = EncryptionUtil.CreateSalt();
     return(new User
     {
         Id = id,
         Name = "Admin",
         Email = "*****@*****.**",
         Password = EncryptionUtil.Hash("admin", salt),
         Salt = salt,
         Dateofbirth = new DateTime(1998, 3, 3),
         Gender = UserGender.Male,
         Type = UserType.Admin
     });
 }
예제 #5
0
 public static User CreateOrganiserUser(int id = 2)
 {
     byte[] salt = EncryptionUtil.CreateSalt();
     return(new User
     {
         Id = id,
         Name = "Frank",
         Email = "*****@*****.**",
         Password = EncryptionUtil.Hash("frank", salt),
         Salt = salt,
         Dateofbirth = new DateTime(1999, 2, 2),
         Gender = UserGender.Male,
         Type = UserType.Organiser
     });
 }
예제 #6
0
        public async Task <User> CreateUser(UserBody userBody)
        {
            // create salt
            byte[] salt = EncryptionUtil.CreateSalt();

            // create user
            User newUser = new User
            {
                Name        = userBody.Name,
                Email       = userBody.Email,
                Password    = EncryptionUtil.Hash(userBody.Password, salt),
                Salt        = salt,
                Dateofbirth = userBody.Dateofbirth,
                Gender      = userBody.Gender,
                Type        = userBody.Type
            };

            // save to database
            newUser = await userRepository.CreateAsync(newUser);

            return(newUser);
        }