Ejemplo n.º 1
0
        public AuthResponse Register(RegisterModel register)
        {
            var userDocument = new UserDocument {
                Id          = Guid.NewGuid(),
                Email       = register.Email,
                FirstName   = register.FirstName,
                LastName    = register.LastName,
                PhoneNumber = register.PhoneNumber,
                DateCreated = DateTime.UtcNow
            };

            var emailModel = new EmailModel
            {
                Reciever = userDocument.Email
            };

            //var emailVerify = _emailGenerator.SendMail(emailModel);

            var salt = _crypto.GenerateSalt(32);

            var encrptedPassword = _crypto.Hash(register.Password, salt, 5523);

            userDocument.LoginProfile = new LoginProfile();

            userDocument.LoginProfile.Password = encrptedPassword;

            userDocument.LoginProfile.Salt = salt;

            var user = _userService.Create(userDocument);

            if (user != null)
            {
                var userInfo = new UserInfo
                {
                    Id            = user.Id,
                    Email         = user.Email,
                    FirstName     = user.FirstName,
                    LastName      = user.LastName,
                    PhoneNumber   = user.PhoneNumber,
                    PassportPhoto = user.PassportPhoto,
                    BVN           = user.BVN,
                    DateCreated   = user.DateCreated
                };
                var token = GenerateJwtToken(userInfo);
                return(new AuthResponse {
                    User = userInfo, Token = token
                });
            }

            throw new UnauthorizedAccessException("User not Created");;
        }
Ejemplo n.º 2
0
        public SignUpInResult SignUp(SignUpRequest request)
        {
            return(BaseInvokeCheckModel(request, () =>
            {
                var responseBuilder =
                    ResponseBuilder <SignUpInResult>
                    .Fail();

                if (_dbContext.Users.Any(x => x.Email == request.Email))
                {
                    return responseBuilder.SetInfoAndBuild("User with this email already registered");
                }

                var salt = _crypto.GenerateSalt();
                var passwordHah = _crypto.HashPassword(salt, request.Password);

                var dataUser = UserMapper.ToData.FromRequest(request, user =>
                {
                    user.Id = Guid.NewGuid();
                    user.IsUploadingAudio = false;
                    user.PasswordHash = passwordHah;
                    user.PasswordSalt = salt;
                    user.RegisterDate = DateTime.Now;
                });

                var dataAuthToken = new AuthToken
                {
                    Id = Guid.NewGuid(),
                    DateExpired = DateTime.Now.AddDays(AuthTokenDaysExpired),
                    UserId = dataUser.Id,
                    IsActive = true
                };

                var playlist = new Playlist
                {
                    Id = Guid.NewGuid(),
                    IsGeneral = true,
                    Title = GeneralPlaylistName,
                    OwnerId = dataUser.Id,
                    OrderValue = 0
                };

                _dbContext.AuthTokens.Add(dataAuthToken);
                _dbContext.Users.Add(dataUser);
                _dbContext.Playlists.Add(playlist);
                _dbContext.SaveChanges();

                return ResponseBuilder <SignUpInResult> .SuccessBuild(new SignUpInResult
                {
                    User = UserMapper.ToApi.FromData(dataUser),
                    AuthToken = AuthTokenMapper.ToApi.FromData(dataAuthToken)
                });
            }));
        }
Ejemplo n.º 3
0
        public async Task <UserAccount> CreateNewLocalUserAccountAsync(string email, string password, string returnUrl = null)
        {
            var now = DateTime.UtcNow;

            var userAccount = new UserAccount
            {
                Id           = Guid.NewGuid(),
                Email        = email,
                PasswordHash = _crypto.HashPassword(password,
                                                    _applicationOptions.PasswordHashingIterationCount),
                FailedLoginCount  = 0,
                IsEmailVerified   = false,
                IsLoginAllowed    = _applicationOptions.RequireLocalAccountVerification,
                PasswordChangedAt = now,
                CreatedAt         = now,
                UpdatedAt         = now
            };

            if (_applicationOptions.RequireLocalAccountVerification &&
                !String.IsNullOrWhiteSpace(returnUrl))
            {
                // Set verification key
                userAccount.SetVerification(
                    _crypto.Hash(_crypto.GenerateSalt()).StripUglyBase64(),
                    VerificationKeyPurpose.ConfirmAccount,
                    returnUrl,
                    now);
            }

            await _userAccountStore.WriteAsync(userAccount);

            // Emit event
            await _eventService.RaiseSuccessfulUserAccountCreatedEventAsync(
                userAccount.Id,
                IdentityServerConstants.LocalIdentityProvider);

            return(userAccount);
        }
Ejemplo n.º 4
0
        public void SetVerification(
            UserAccount userAccount,
            VerificationKeyPurpose purpose,
            string storage  = null,
            DateTime?sentAt = null)
        {
            userAccount.VerificationKey = crypto
                                          .Hash(crypto.GenerateSalt())
                                          .StripUglyBase64()
                                          .ToLowerInvariant();

            userAccount.VerificationPurpose   = (int)purpose;
            userAccount.VerificationKeySentAt = sentAt ?? DateTime.UtcNow;
            userAccount.VerificationStorage   = storage;
        }