Пример #1
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);
        }
Пример #2
0
        public static bool AddUser(string Username, string Password, string First_name, string Last_name, string Email, List <int> Grupo, List <int> Permisos, bool Is_superuser, bool Is_staff, bool Is_active)
        {
            UserEntity userUserEntity = new UserEntity();

            userUserEntity.username         = Username;
            userUserEntity.password         = Password;
            userUserEntity.first_name       = First_name;
            userUserEntity.last_name        = Last_name;
            userUserEntity.email            = Email;
            userUserEntity.groups           = Grupo;
            userUserEntity.user_permissions = Permisos;
            userUserEntity.is_active        = Is_active;
            userUserEntity.is_staff         = Is_staff;
            userUserEntity.is_superuser     = Is_superuser;
            UserAPI userapi = new UserAPI();

            return(userapi.AddUser(userUserEntity));
        }