public void ProcessRequest(HttpContext context) { string json; try { var repo = new Repository(); API.LoginRequestParams requestParams = API.GetLoginRequestParams(GetRequestBody(context)); User user = repo.Login(requestParams.Username, requestParams.Password); if (user != null) { Token token = repo.GetOrCreateToken(user); // If authorizing via PM auth command, store the UserID for this auth token if (!string.IsNullOrEmpty(requestParams.SUID)) { repo.MatchUserToAuthToken(user, requestParams.SUID); repo.SaveChanges(); } List<FirstChannelVisit> channelsVisited = repo.GetFirstChannelVisits(user.UserID); // TODO: Merge this up foreach (var chan in channelsVisited) chan.DateVisitDisplay = chan.DateVisit.ToString(); json = JsonConvert.SerializeObject(new { success = true, User = PlainUser.FromModel(user), Token = PlainToken.FromModel(token), ChannelsVisited = channelsVisited }); } else { json = JsonConvert.SerializeObject(new { success = false, UserMessage = "Invalid login." }); } } catch (Exception ex) { json = JsonConvert.SerializeObject(new { success = false, error = "There was an exception: " + ex.Message }); } SetNoCaching(context); context.Response.ContentType = "text/json"; context.Response.Write(json); }
public void ProcessRequest(HttpContext context) { string json; try { var requestBody = context.Request.Form["RequestBody"]; var requestParams = API.GetAuthRequestParams(requestBody); var repo = new Repository(); if (repo.HaveAuth(requestParams.NetworkID, requestParams.Nick, requestParams.Username, requestParams.Host)) { json = JsonConvert.SerializeObject(new { success = true, alreadyAuthenticated = true }); } else { // Create a new auth record for the user, give him the UID for the web Auth auth = new Auth { FKNetworkID = requestParams.NetworkID, Nick = requestParams.Nick, Username = requestParams.Username, Host = requestParams.Host, SUID = Utils.Get32ByteUID(), DateIssued = DateTime.UtcNow }; repo.AddAuth(auth); repo.SaveChanges(); json = JsonConvert.SerializeObject(new { success = true, ID = auth.AuthID, SUID = auth.SUID }); } } catch (Exception ex) { json = JsonConvert.SerializeObject(new { success = false, error = "There was an exception: " + ex.Message }); } SetNoCaching(context); context.Response.ContentType = "text/json"; context.Response.Write(json); }
public void ProcessRequest(HttpContext context) { string json; try { var requestParams = API.GetMeRequestParams(GetRequestBody(context)); var repo = new Repository(); // Verify user token var user = repo.VerifyLoginToken(requestParams.Token); if (user != null) { repo.UpdateSignature(user, requestParams.Signature); repo.SaveChanges(); json = JsonConvert.SerializeObject(new { success = true }); } else { json = JsonConvert.SerializeObject(new { success = false }); } } catch (Exception ex) { json = JsonConvert.SerializeObject(new { success = false, error = "There was an exception: " + ex.Message }); } SetNoCaching(context); context.Response.ContentType = "text/json"; context.Response.Write(json); }