public Session GetLoginSession(string username, string password) { Session httpResponse = new Session(); Logging.Info("request", "Received request for GetLoginSession"); Logging.Info("GetLoginSession", "username: "******"GetLoginSession", "Begins."); UserInformation userInformation = SessionHelpers.Login(username, password); if (userInformation == null) { statusCode = (int)HttpStatusCode.Forbidden; httpResponse.Message = "boom"; } else { httpResponse.Message = "good"; httpResponse.username = userInformation.userName; Random random = new System.Random(); string sessionId; while (true) { sessionId = GenericHelpers.CreateMD5(random.Next(114514, 1919810).ToString()); string sessionKeyName = "EARTH_FUSION_SESSION_" + sessionId; if (RedisHelpers.GetString(sessionKeyName) == null) { RedisHelpers.SetString(sessionKeyName, userInformation.userId.ToString()); // three hour RedisHelpers.SetKeyExpireTime(sessionKeyName, 3 * 60 * 60); break; } } httpResponse.sessionId = sessionId; } httpResponse.StatusCode = statusCode; this.HttpContext.Response.StatusCode = statusCode; Logging.Info("request", "Reponse returned for GetLoginSession"); return(httpResponse); }
public RedisSetStringResult TestRedisSetString(string keyName, string value) { RedisSetStringResult httpResponse = new RedisSetStringResult(); httpResponse.Date = DateTime.Now; httpResponse.KeyName = keyName; httpResponse.Value = value; int statusCode = (int)HttpStatusCode.OK; if (RedisHelpers.SetString(keyName, value)) { httpResponse.Message = "Set success"; } else { statusCode = (int)HttpStatusCode.InternalServerError; httpResponse.Message = "Something not good happened..."; } this.HttpContext.Response.StatusCode = statusCode; httpResponse.StatusCode = statusCode; return(httpResponse); }
public static bool RequestVerificationCode(string emailAddress) { string verificationCodeSentString = RedisHelpers.GetString("earth_fusion_" + emailAddress + "_verification_code_sent"); if (verificationCodeSentString != null) { // already has an code. return(false); } Random random = new System.Random(); // 6 digit int verificationCode = random.Next(100000, 999999); string verificationCodeString = verificationCode.ToString(); SendgridHelpers.SendVerificationCodeTask(emailAddress, "User", verificationCodeString); // set redis RedisHelpers.SetString("earth_fusion_" + emailAddress + "_verification_code", verificationCodeString); RedisHelpers.SetString("earth_fusion_" + emailAddress + "_verification_code_sent", "1"); // set verification code timeout: 600s (10 min) RedisHelpers.SetKeyExpireTime("earth_fusion_" + emailAddress + "_verification_code", 600); // set timeout for when can user request another verification code: 60 (1 min) RedisHelpers.SetKeyExpireTime("earth_fusion_" + emailAddress + "_verification_code_sent", 60); return(true); }