Esempio n. 1
0
        public async Task <IActionResult> RegisterNewUser(UserCreationRequest request)
        {
            if (!IdGenerator.IsType(request.UserId, IdType.User))
            {
                return(BadRequest());
            }


            var rootDirectoryId = IdGenerator.NewId(IdType.Directory);

            try
            {
                var successful = await userManager.InsertUser(
                    request.UserId,
                    rootDirectoryId,
                    request.Email,
                    request.HashedPassword,
                    request.Salt,
                    request.PublicKey,
                    request.EncryptedPrivateKey);

                if (!successful)
                {
                    return(BadRequest());
                }
            }
            catch (InvalidParameterException)
            {
                throw;
            }
            catch (ObjectNotResolvableException)
            {
                throw;
            }
            catch (UnexpectedBehaviourException)
            {
                throw;
            }
            catch (DatabaseException e)
            {
                throw new DatabaseException("Database error during file delete. See inner exception.", e);
            }
            catch (Exception e)
            {
                throw new Exception("Unknown error during file delete. See inner exception.", e);
            }



            return(Ok());
        }
        public static async Task <BasicUser> GenerateUser(this IDbUserManager userManager)
        {
            var userId         = IdGenerator.NewId(IdType.User);
            var rootDirId      = IdGenerator.NewId(IdType.Directory);
            var hashedPassword = "******";
            var salt           = "Salt";
            var email          = userId + "@test.corp";
            var keys           = CryptoHelper.GenerateRsaKeyPair();

            await userManager.InsertUser(userId, rootDirId, email, hashedPassword, salt,
                                         keys.PublicKey, keys.PrivateKey);

            return(new BasicUser(userId, rootDirId, email));
        }