| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Net.Http;
- using System.Web;
- using System.Web.Mvc;
- namespace NEducation.Controllers
- {
- public class BaseController : Controller
- {
- // GET: Base
- // GET: Base
- public class ReCaptcha
- {
- public bool Success { get; set; }
- public List<string> ErrorCodes { get; set; }
- public static bool Validate(string encodedResponse)
- {
- if (string.IsNullOrEmpty(encodedResponse)) return false;
- var client = new System.Net.WebClient();
- var secret = ConfigurationManager.AppSettings[UtilsController.WsType.GoogleCaptcha];
- if (string.IsNullOrEmpty(secret)) return false;
- var googleReply = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secret, encodedResponse));
- var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
- var reCaptcha = serializer.Deserialize<ReCaptcha>(googleReply);
- return reCaptcha.Success;
- }
- }
- public static string CheckAutoLogin(log4net.ILog log, String uuid)
- {
- string res = null;
- try
- {
- HttpClient httpClient = new HttpClient();
- MultipartFormDataContent form = new MultipartFormDataContent();
- form.Add(new StringContent(uuid), "uuid");
- form.Add(new StringContent("mocha"), "username");
- form.Add(new StringContent("mocha@%23$2014"), "password");
- using (var client = new HttpClient())
- {
- var response = client.PostAsync(UtilsController.WsType.URL_GET_MSISDN, form).Result;
- log.Debug("url: " + UtilsController.WsType.URL_GET_MSISDN);
- if (response.IsSuccessStatusCode)
- {
- var responseContent = response.Content;
- // by calling .Result you are synchronously reading the result
- string responseString = responseContent.ReadAsStringAsync().Result;
- log.Debug("Response: " + responseString);
- return responseString;
- }
- else
- {
- log.Debug("Response: " + response.StatusCode.ToString());
- return response.StatusCode.ToString();
- }
- }
- }
- catch (Exception ex)
- {
- log.Debug("Exp: " + ex);
- }
- return res;
- }
- protected bool CheckAuthToken()
- {
- if (Session["AuthToken"] != null && Request.Cookies["AuthToken"] != null)
- {
- if (!Session["AuthToken"].ToString().Equals(Request.Cookies["AuthToken"].Value))
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- else
- {
- return false;
- }
- }
- }
- }
|