public async Task <DropshipAccount> GetAccount(string username) { //Check cache for account info var accountInfo = new DropshipAccount() { Username = username }; if (await cache.Exists(RedisKeyConvert.Serialize(accountInfo))) { return(JsonConvert.DeserializeObject <DropshipAccount>(await cache.GetString(RedisKeyConvert.Serialize(accountInfo)))); } //Couldn't find it in the cache, look in db accountInfo = await dbAccounts.GetOneByUsername(username); if (accountInfo != null) { return(accountInfo); } //Couldn't find it in db, must be a new account accountInfo = new DropshipAccount() { Username = username, Status = AccountStatus.New }; return(accountInfo); }
public async Task <DropshipAccount> SetupAccount(DropshipAccountConfiguration account, string username) { var dropshipAccount = new DropshipAccount() { Username = username, Status = AccountStatus.Existing, Subscription = account.Subscription }; await dbAccounts.CreateAccount(dropshipAccount); return(dropshipAccount); }
public string CreateJWT(UserLoginModel user, DropshipAccount account) { var claims = new List <Claim> { new Claim(ClaimTypes.Name, user.Username.ToLower()) }; if (account.Status == AccountStatus.Existing) { claims.Add(new Claim(ClaimTypes.Role, account.Subscription)); } return(jwtFactory.GenerateToken(claims.ToArray())); }
public async Task <bool> AddShopifyIntegration(DropshipAccount account, ShopifyOAuthResponse oauth, ShopifyOAuth verify) { var username = account.Username; var endpoint = ShopifyEndpoints.OAuthEndpoint(oauth.Shop); var requestType = new { client_id = config.ClientID, client_secret = config.ClientSecret, code = oauth.Code }; var requestContent = JsonConvert.SerializeObject(requestType, jsonSettings); var content = new JsonContent(requestContent); var response = await http.Post(endpoint, content); string message = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { var tokenResponse = JsonConvert.DeserializeObject <ShopifyOAuthAccessResponse>(message, jsonSettings); verify.VerifyScope(tokenResponse.Scope); await oauthDb.CreateOAuth(new OAuthAccountModel() { AccessToken = tokenResponse.AccessToken, Username = username, Service = "Shopify", Extra = new Dictionary <string, string>() { { "Shop", oauth.Shop } }, AccountID = account.ID }); return(true); } else { return(false); } }