/// <summary> /// Changes the name of the user. /// </summary> /// <param name="name">New name</param> /// <returns>Async task</returns> public async Task ChangeNameAsync(string name) { // Creates addables List <IReqAddable> addables = LoginCookies.Select(x => (IReqAddable) new GuildedCookie(x.Name, x.Value)).ToList(); addables.Add(new JsonBody($"{{\"name\": \"{name}\"}}")); // Executes it await ExecuteRequest <object>(new Endpoint($"/users/{CurrentUser.Id}/profilev2", Method.POST), addables.ToArray()); }
/// <summary> /// Sends a message to the specific channel. /// </summary> /// <param name="channel">ID of the channel</param> /// <param name="message">Message</param> /// <returns>Async task</returns> public async Task <object> SendMessageAsync(Guid channel, NewMessage message) { // Creates addables List <IReqAddable> addables = LoginCookies.Select(x => (IReqAddable) new GuildedCookie(x.Name, x.Value)).ToList(); addables.Add(new JsonBody(JsonConvert.SerializeObject(message, Converters))); // Execute it return(await ExecuteRequest <object>(new Endpoint($"channels/{channel}/messages", Method.POST), addables.ToArray())); }
public CustomerView PersistLogin() { CustomerView customer; //check if session existed string sessionValue = session.GetString(customerSessionKeyWord); if (sessionValue != null) { customer = eCommerce.GetCustomerBy(int.Parse(sessionValue)); if (customer != null) { if (customer.Active) { return(customer); } } session.Remove(customerSessionKeyWord); return(null); } LoginCookies loginCookies = requestCookies.GetJson <LoginCookies>(customerCookieKeyWord); if (loginCookies == null) { return(null); } customer = eCommerce.GetCustomerBy(loginCookies.UserId); if (customer == null) { responseCookies.Delete(customerCookieKeyWord); return(null); } if (!customer.Active) { responseCookies.Delete(customerCookieKeyWord); return(null); } string loginValue = EncryptionService.Encrypt(customer.Email + eCommerce.GetCustomerEncryptedPassword(int.Parse(customer.Id)) + connectionInfo.RemoteIpAddress.ToString()); if (loginCookies.LoginValue != loginValue) { responseCookies.Delete(customerCookieKeyWord); return(null); } session.SetString(customerSessionKeyWord, customer.Id); return(customer); }
public SellerView PersistLogin() { SellerView seller; string sessionValue = session.GetString(sellerSessionKeyWord); if (sessionValue != null) { seller = eCommerce.GetSellerBy(int.Parse(sessionValue)); if (seller != null) { if (seller.Status != SellerStatus.Locked) { return(seller); } } session.Remove(sellerSessionKeyWord); return(null); } LoginCookies loginCookies = requestCookies.GetJson <LoginCookies>(sellerCookieKeyWord); if (loginCookies == null) { return(null); } seller = eCommerce.GetSellerBy(loginCookies.UserId); if (seller == null) { responseCookies.Delete(sellerCookieKeyWord); return(null); } if (seller.Status == SellerStatus.Locked) { responseCookies.Delete(sellerCookieKeyWord); return(null); } string loginValue = EncryptionService.Encrypt(seller.Email + eCommerce.GetSellerEncryptedPassword(int.Parse(seller.Id)) + connectionInfo.RemoteIpAddress.ToString()); if (loginCookies.LoginValue != loginValue) { responseCookies.Delete(sellerCookieKeyWord); return(null); } session.SetString(sellerSessionKeyWord, seller.Id); return(seller); }
public AdminView PersistLogin() { AdminView admin; string sessionValue = session.GetString(adminSessionKeyWord); if (sessionValue != null) { admin = eCommerce.GetAdminBy(int.Parse(sessionValue)); if (admin != null) { return(admin); } session.Remove(adminSessionKeyWord); return(null); } LoginCookies loginCookies = requestCookies.GetJson <LoginCookies>(adminCookieKeyWord); if (loginCookies == null) { return(null); } admin = eCommerce.GetAdminBy(loginCookies.UserId); if (admin == null) { responseCookies.Delete(adminCookieKeyWord); return(null); } string loginValue = EncryptionService.Encrypt(admin.Email + eCommerce.GetAdminEncryptedPassword(int.Parse(admin.Id)) + connectionInfo.RemoteIpAddress.ToString()); if (loginCookies.LoginValue != loginValue) { responseCookies.Delete(adminCookieKeyWord); return(null); } session.SetString(adminSessionKeyWord, admin.Id); return(admin); }