Exemple #1
0
        public async Task <AdminLoginResponseModel> LogInAsync(AdminLogInRequestModel model)
        {
            await _sessionService.DeleteAsync();

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

            if (user == null)
            {
                throw new ApiException("Неверный email", 400);
            }

            bool ok = await _userManager.CheckPasswordAsync(user, model.Password);

            if (!ok)
            {
                throw new ApiException("Неверный пароль", 400);
            }

            string role    = (await _userManager.GetRolesAsync(user)).First();
            string token   = JWTHelper.Create(user.Id, role, out long expiresIn);
            Guid   refresh = await _sessionService.CreateAsync(user.Id);

            if (model is LoginRequestModel clientModel)
            {
                await _connectionService.AddAsync(user.Id, clientModel.PlayerId);
            }

            return(new AdminLoginResponseModel(user, token, refresh, expiresIn, role, user.ManagedRestaurantId));
        }
        public async Task <IActionResult> LogIn([FromBody] AdminLogInRequestModel model)
        {
            AdminLoginResponseModel result = await _authService.LogInAsync(model);

            return(Ok(result));
        }