protected async Task <TResponse> SendRequest <TRequest, TResponse>(TRequest request, CancellationToken cancellationToken = default(CancellationToken)) where TRequest : class where TResponse : class { return(await BusControl.SendRequest <TRequest, TResponse>(request, cancellationToken)); }
public void Validate(TModel model) { var query = new GetUserByEmail(model.Email); var result = BusControl.SendRequest <IGetUserByEmail, IGetUserResult>(query).Result; if (result.User != null) { throw new Exception(ExceptionInfo.EmailAlreadyExists.Message); } }
public async Task Token(TokenUserModel model) { if (!ModelState.IsValid) { Response.StatusCode = 400; await Response.WriteAsync("username or password cannot be empty"); return; } var email = model.UserName; //Request.Form["username"]; var password = model.Password; //Request.Form["password"]; var query = new GetUserByEmail(email); var result = BusControl.SendRequest <IGetUserByEmail, IGetUserResult>(query).Result; var identity = AuthOptions.GetIdentity(email, password, result.User.PasswordHash, result.User.RoleName); if (identity == null) { Response.StatusCode = 400; await Response.WriteAsync("Invalid username or password."); return; //return BadRequest("Invalid username or password."); } var encodedJwt = AuthOptions.Token(identity); var response = new { accesstoken = encodedJwt, username = identity.Name }; // сериализация ответа Response.ContentType = "application/json"; await Response.WriteAsync(JsonConvert.SerializeObject(response, new JsonSerializerSettings { Formatting = Formatting.Indented })); }
public static IGetUserResult GetUser(string email) { var query = new GetUserByEmail(email); return(BusControl.SendRequest <IGetUserByEmail, IGetUserResult>(query).Result); }