Пример #1
0
        public async Task <IActionResult> Register(UserDm user)
        {
            //validate request

            user.UserName = user.UserName.ToLower();

            if (await _authRepository.UserExists(user.UserName))
            {
                return(BadRequest("Username already exists."));
            }

            var userToCreate = _mapper.Map <User>(user);

            userToCreate.UserGroups = user.UserGroup.Select(x => new UserUserGroup
            {
                UserGroup = new UserGroup {
                    Id = x
                },
                User = userToCreate
            }).ToList();
            await _authRepository.Register(userToCreate, user.Password);

            var userToReturn = _mapper.Map <UserDetailsDm>(userToCreate);

            return(Ok(userToReturn));
        }
Пример #2
0
        public UserDm Add(UserDm user)
        {
            var addedUser = userRepository.Add(new User
            {
                UserId              = user.UserId,
                UserEmailId         = user.UserEmailId,
                UserGender          = user.UserGender,
                UserEmailIdVerified = user.UserEmailIdVerified,
                UserProfilePicUrl   = user.UserProfilePicUrl,
                UserIsActive        = user.UserIsActive,
                CreatedOn           = user.CreatedOn,
                ModifiedOn          = user.ModifiedOn
            });

            if (addedUser == null)
            {
                return(null);
            }

            return(new UserDm
            {
                UserId = addedUser.UserId,
                UserEmailId = addedUser.UserEmailId,
                UserGender = addedUser.UserGender,
                UserEmailIdVerified = addedUser.UserEmailIdVerified,
                UserProfilePicUrl = addedUser.UserProfilePicUrl,
                UserIsActive = addedUser.UserIsActive,
                CreatedOn = addedUser.CreatedOn,
                ModifiedOn = addedUser.ModifiedOn
            });
        }
Пример #3
0
        public bool SendEmailVerificationLink(UserDm user)
        {
            var token = userRepository.GetEmailVerificationToken(user.UserId);

            if (token == null)
            {
                return(false);
            }

            return(emailHelper.SendEmail(user.UserEmailId, null, null,
                                         "Verify Email | DocStore", $"http://localhost:7000/users/{user.UserId}/email/verify/{token}"));
        }
Пример #4
0
        public async Task <IActionResult> Register(UserDm user)
        {
            //validate request

            user.Username = user.Username.ToLower();

            if (await _authRepository.UserExists(user.Username))
            {
                return(BadRequest("Username already exists."));
            }

            var userToCreate = _mapper.Map <User>(user);

            await _authRepository.Register(userToCreate, user.Password);

            var userToReturn = _userMapper.MapEmToDm(userToCreate);

            return(CreatedAtRoute("GetUser", new{ controller = "Users", id = userToReturn.Id }, userToReturn));
        }