Пример #1
0
        public async Task <AuthorizationResponseModel> RegisterAsync(AuthorizationRequestModel registrationModel)
        {
            RoleData role = applicationRoleRepository.Get(registrationModel.Role);
            RegistrationResponseModel response = new RegistrationResponseModel()
            {
                IsSuccessful = false, Message = string.Empty
            };
            var userData = new UserData
            {
                Email    = registrationModel.Email,
                Password = registrationModel.Password,
                RoleId   = role.Id
            };

            IdentityResult userCreatingResult = await applicationUserRepository.CreateAsync(userData);

            if (!userCreatingResult.Succeeded)
            {
                // pushing message of first error in array
                response.Message = GetErrorMessage(userCreatingResult);
                return(response);
            }

            userData = await applicationUserRepository.FindByEmailAsync(userData.Email);

            ClientData client = new ClientData()
            {
                Name      = registrationModel.UserName,
                Surname   = registrationModel.Surname,
                PhotoPath = "default/profile.png",
                UserId    = userData.Id
            };
            ClientData addedClient = await clientRepository.AddAsync(client);

            if (addedClient == null)
            {
                response.Message = "Client not added";
            }
            response.IsSuccessful = true;
            string token       = javascriptWebTokenFactory.Create(userData.Id);
            var    sessionData = new SessionData
            {
                UserId = userData.Id,
                Token  = token,
            };
            await sessionRepository.CreateAsync(sessionData);

            response.Token = token;
            return(response);
        }
Пример #2
0
        public async Task Search_User_By_Email()
        {
            ApplicationUser applicationUser = await _applicationUserRepository.FindByEmailAsync("*****@*****.**");

            Assert.IsNotNull(applicationUser);
            Assert.AreEqual("*****@*****.**", applicationUser.Email);
        }
Пример #3
0
 public Task <ApplicationUser> FindByEmailAsync(string email)
 {
     return(_userRepository.FindByEmailAsync(email));
 }