예제 #1
0
        public async Task <UserSession> LoginAsync(LoginRequest lr)
        {
            UserProfile profile = await FindByUsernameAsync(lr.Username);

            if (profile == null)
            {
                throw new ValidationException("username does not exists");
            }

            if (PasswordUtil.encode(lr.Password).Equals(profile.Password))
            {
                UserSession us = new UserSession()
                {
                    CreatedAt = DateTime.Now,
                    UserId    = profile.Id
                };

                await userSessionRepository.InsertAsync(us);

                return(us);
            }

            throw new ValidationException("Invalid password");
        }