public async Task <IActionResult> Login([FromBody] UserLoginForm user) { var loginCheck = await _authService.CheckUser(user.Email, user.Password); if (!loginCheck) { throw new HttpStatusCodeException(HttpStatusCode.Unauthorized, _localizer["Wrong password or email"]); } var accessToken = await _authService.GetAccessToken(user.Email, user.Password); var refreshToken = await _authService.GetRefreshToken(user.Email, user.Password); var userData = await _userService.GetUserData(user.Email); var response = new AuthLoginResponse(); response.Address = userData.Address; response.City = userData.City; response.Name = userData.Name; response.NIP = userData.NIP == null ? (int?)null : int.Parse(userData.NIP); response.PostCode = userData.PostCode; response.State = userData.State; response.AccessToken = accessToken; response.RefreshToken = refreshToken; response.Email = user.Email; return(accessToken != null && refreshToken != null && userData != null ? (IActionResult)StatusCode(200, response) : StatusCode(500)); }
public SyncSession SendAsync(AuthLoginResponse value) => SendAsync(ClientOpcode.LoginResult, (PacketWriter writer) => { writer.Write(value.AccountId); writer.Write(byte.MinValue); writer.Write(value.Response == AuthLoginStatus.Failure ? new byte[18] : Encoding.ASCII.GetBytes(value.Mac)); writer.WriteByteLengthUnicodeString(value.ErrorMessage); writer.WriteAuthLoginErrorMessageCode(value.ErrorMessageCode); writer.Write(byte.MinValue); writer.Write(byte.MinValue); writer.WriteByteLengthUnicodeString(value.ErrorMessage); writer.Write(value.SessionKey); writer.Write(byte.MinValue); writer.Write(uint.MinValue); writer.Write(uint.MinValue); writer.Write(byte.MinValue); });
public async Task <AuthLoginResponse> Login(Guid businessId, AuthLoginRequest request) { var user = await UserManager.FindByEmailAsync(request.Email); if (user == null) { throw new KeyNotFoundException("Invalid Email"); } var check = await SignInManager.CheckPasswordSignInAsync(user, request.Password, false); if (!check.Succeeded) { throw new AppException("Invalid Password"); } if (user.BusinessId != businessId) { throw new AppException("Invalid, User not registered to this business"); } var roles = await UserManager.GetRolesAsync(user); var response = AuthHelper.WriteJwt(user, roles, _appSettings); var returnValue = new AuthLoginResponse() { Email = user.Email, Name = user.FullName, Id = user.Id, PhoneNumber = user.PhoneNumber, Token = response.Token, TokenExpirationDate = response.Expiration }; return(returnValue); }