示例#1
0
        public async Task <ActionResult <object> > Login([FromBody] LoginRegisterDtoModel model)
        {
            var result = await this._signInManager.PasswordSignInAsync(model.Email, model.Password, false, false);

            if (!result.Succeeded)
            {
                return(this.BadRequest("INVALID_LOGIN_ATTEMPT"));
            }

            var appUser = this._userManager.Users.SingleOrDefault(r => r.Email == model.Email);

            return(this.GenerateJwtToken(model.Email, appUser));
        }
示例#2
0
        public async Task <ActionResult <object> > Register([FromBody] LoginRegisterDtoModel model)
        {
            var user = new ApplicationUserModel
            {
                UserName = model.Email,
                Email    = model.Email,
            };
            var result = await this._userManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return(this.BadRequest(result.Errors));
            }

            await this._signInManager.SignInAsync(user, false);

            return(this.GenerateJwtToken(model.Email, user));
        }