Example #1
0
        /// <summary>
        /// Method for login new users
        /// </summary>
        /// <param name="model"></param>
        /// <returns>Returns token</returns>
        public async Task <string> LoginToken(LoginModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                throw new AuthenticationException($"User {model.Email} user does not exist");
            }
            var result = await _signManager.PasswordSignInAsync(model.Email, model.Password, false, false);

            return(result.Succeeded ? _token.GenerateJwt(user) : throw new AuthenticationException("Error during authorization"));
        }