| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439 |
- using log4net;
- using LuckyCallWebCore.Source;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using ServiceAPI;
- using System;
- using LuckyCallWebCore.Extensions;
- using LuckyCallWebCore.Models;
- using Microsoft.Extensions.Primitives;
- using Newtonsoft.Json;
- using System.ServiceModel;
- using System.ServiceModel.Channels;
- using System.Threading.Tasks;
- namespace LuckyCallWebCore.Controllers
- {
- public class SubscriberController : BaseController
- {
- private static ILog log = LogManager.GetLogger("SubscriberController");
- ServiceAPI.WsLuckyCallClient wsClient = new ServiceAPI.WsLuckyCallClient();
- [HttpPost]
- [ValidateAntiForgeryToken]
- public JsonResult Subscribe(String msisdn, String packName)
- {
- if (msisdn == null || msisdn.Trim() == "")
- {
- msisdn = HttpContext.Session.GetString("msisdn");
- }
- if (msisdn != "" && msisdn != null)
- {
- msisdn = validateMsisdn(msisdn);
- SetWsClient(ref wsClient, msisdn);
- //ServiceAPI.response subInfo = wsClient.wsGetSubInfo(wsUser, wsPassword, msisdn);
- ServiceAPI.response res = null;
- res = wsClient.wsRegisterSubOtp(wsUser, wsPassword, msisdn, packName);
- if (res.errorCode == "0")
- {
- // success
- }
- else if (res.errorCode == "100")
- {
- // need confirm
- RequestTemp reqTemp = new RequestTemp();
- reqTemp.packName = packName;
- reqTemp.requestId = res.resultCode;
- reqTemp.msisdn = msisdn;
- Session["reqTemp"] = reqTemp;
- }
- return Json(new
- {
- error = res.errorCode,
- content = res.content,
- msisdn = msisdn.Substring(3)
- });
- }
- else
- {
- return Json(new
- {
- error = "-1",
- content = Lang.InvalidMsisdn
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult SubscribeConfirm(String otp)
- {
- RequestTemp reqTemp = Session["reqTemp"] as RequestTemp;
- if (reqTemp == null)
- {
- return Json(new
- {
- error = "-1",
- content = "Timeout",
- href = "/Home/Index"
- });
- }
- String msisdn = reqTemp.msisdn;
- if (msisdn != "" && msisdn != null)
- {
- CommonUtils.SetWsClient(ref wsClient, Session.SessionID);
- //ServiceAPI.response subInfo = wsClient.wsGetSubInfo(wsUser, wsPassword, msisdn);
- ServiceAPI.response res = null;
- String channel = ConfigurationManager.AppSettings["reddemChannel"];
- res = wsClient.wsRegisterSubConfirm(wsUser, wsPassword, msisdn, reqTemp.packName, otp);
- if (res.errorCode == "0")
- {
- // login success --> store session
- Session["msisdn"] = msisdn;
- Session["account"] = wsClient.wsGetSubInfo(wsUser, wsPassword, msisdn);
- }
- return Json(new
- {
- error = res.errorCode,
- content = res.content,
- msisdn = msisdn.Substring(3)
- });
- }
- else
- {
- return Json(new
- {
- error = "-1",
- content = "Timeout"
- });
- }
- }
- [HttpPost]
- [ValidateAntiForgeryToken]
- public JsonResult LoginAction(String phoneNumber, string password, string captcharesponse)
- {
- String msisdn = CommonUtils.validateMsisdn(phoneNumber);
- CheckSessionRes checkSession = CheckSessionValid(ActionSession.Login);
- if (checkSession.errorCode != "0")
- {
- return Json(new
- {
- error = checkSession.errorCode,
- content = checkSession.content,
- msisdn = msisdn.Substring(3)
- });
- }
- if (msisdn != "")
- {
- ServiceAPI.response subInfo = null;
- CommonUtils.SetWsClient(ref wsClient, Session.SessionID);
- ServiceAPI.response res = wsClient.wsLogin(wsUser, wsPassword, password, msisdn);
- if (res.errorCode == "0")
- {
- // login success --> store session
- Session["msisdn"] = msisdn;
- subInfo = wsClient.wsGetSubInfo(wsUser, wsPassword, msisdn);
- Session["account"] = subInfo;
- LoginSuccessAction();
- }
- else
- {
- LoginFailAction();
- }
- if (subInfo != null)
- {
- return Json(new
- {
- error = res.errorCode,
- content = res.content,
- msisdn = msisdn.Substring(3)
- });
- }
- else
- {
- return Json(new
- {
- error = res.errorCode,
- content = res.content,
- msisdn = msisdn.Substring(3)
- });
- }
- }
- else
- {
- return Json(new
- {
- error = "-1",
- content = Lang.InvalidMsisdn
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult SignupAction(String phoneNumber, string captcharesponse)
- {
- //if (Check(captcharesponse) == false)
- //{
- // return Json(new
- // {
- // error = "16",
- // content = Lang.CaptchaInvalid
- // });
- //}
- CheckSessionRes checkSession = CheckSessionValid(ActionSession.SignUp);
- if (checkSession.errorCode != "0")
- {
- return Json(new
- {
- error = checkSession.errorCode,
- content = checkSession.content
- });
- }
- String msisdn = CommonUtils.validateMsisdn(phoneNumber);
- if (msisdn != "")
- {
- CommonUtils.SetWsClient(ref wsClient, Session.SessionID);
- ServiceAPI.response res = wsClient.wsCreateAccount(wsUser, wsPassword, "", msisdn, "1");
- if (res.errorCode == "0")
- {
- // signup success --> store session
- SetLastSignUp();
- Session["msisdn"] = msisdn;
- ViewBag.msisdn = msisdn;
- CommonUtils.SetWsClient(ref wsClient, Session.SessionID);
- ServiceAPI.response subInfo = wsClient.wsGetSubInfo(wsUser, wsPassword, msisdn);
- Session["account"] = subInfo;
- }
- return Json(new
- {
- error = res.errorCode,
- content = res.content,
- msisdn = msisdn.Substring(3)
- });
- }
- else
- {
- return Json(new
- {
- error = "-1",
- content = Lang.InvalidMsisdn
- });
- }
- }
- [ValidateAntiForgeryToken]
- public JsonResult ResetPassword(String phoneNumber, string captcharesponse)
- {
- //if (Check(captcharesponse) == false)
- //{
- // return Json(new
- // {
- // error = "16",
- // content = Lang.CaptchaInvalid
- // });
- //}
- CheckSessionRes checkSession = CheckSessionValid(ActionSession.Resetpass);
- if (checkSession.errorCode != "0")
- {
- return Json(new
- {
- error = checkSession.errorCode,
- content = checkSession.content
- });
- }
- String wsUser = ConfigurationManager.AppSettings["wsUser"];
- String wsPassword = ConfigurationManager.AppSettings["wsPassword"];
- String msisdn = CommonUtils.validateMsisdn(phoneNumber);
- if (msisdn != "")
- {
- ServiceAPI.WsMillionClient wsClient = new ServiceAPI.WsMillionClient();
- CommonUtils.SetWsClient(ref wsClient, Session.SessionID);
- ServiceAPI.response res = wsClient.wsResetPassword(wsUser, wsPassword, msisdn);
- SetLastResetPass();
- return Json(new
- {
- error = res.errorCode,
- content = res.content
- });
- }
- else
- {
- return Json(new
- {
- error = "-1",
- content = Lang.InvalidMsisdn
- });
- }
- }
- [HttpPost]
- public JsonResult CancelService()
- {
- String msisdn = Session["msisdn"] as String;
- if (msisdn != "" && msisdn != null)
- {
- wsClient.Endpoint.Address = GetWsEndpoint();
- var res = wsClient.wsCancelService(wsUser, wsPassword, msisdn);
- if (res.errorCode == "0")
- {
- Session["account"] = wsClient.wsGetSubInfo(wsUser, wsPassword, msisdn);
- }
- return Json(new
- {
- error = res.errorCode,
- content = res.content,
- msisdn = msisdn.Substring(3)
- });
- }
- else
- {
- return Json(new
- {
- error = "-1"
- });
- }
- }
- [HttpPost]
- public JsonResult BuyTurnOtp(String numTurn)
- {
- String msisdn = Session["msisdn"] as String;
- if (msisdn != "" && msisdn != null)
- {
- log.Info("BuyTurn " + msisdn + ", numTurn: " + numTurn);
- wsClient.Endpoint.Address = GetWsEndpoint();
- response res = wsClient.wsBuyTurnOtp(wsUser, wsPassword, msisdn, numTurn);
- return Json(new
- {
- error = res.errorCode,
- content = res.content,
- msisdn = msisdn.Substring(3),
- numTurn = numTurn
- });
- }
- else
- {
- return Json(new
- {
- error = "-1"
- });
- }
- }
- [HttpPost]
- public JsonResult BuyTurnConfirm(String otp, String numTurn)
- {
- String msisdn = Session["msisdn"] as String;
- if (msisdn != "" && msisdn != null)
- {
- log.Info("BuyTurnConfirm " + msisdn + ", numTurn: " + numTurn);
- wsClient.Endpoint.Address = GetWsEndpoint();
- response res = wsClient.wsBuyTurn(wsUser, wsPassword, msisdn, numTurn, otp);
- log.Info("BuyTurnConfirm " + msisdn + ": " + res.errorCode);
- if (res.errorCode == "0")
- {
- Session["account"] = wsClient.wsGetSubInfo(wsUser, wsPassword, msisdn);
- }
- return Json(new
- {
- error = res.errorCode,
- content = res.content,
- msisdn = msisdn.Substring(3)
- });
- }
- else
- {
- return Json(new
- {
- error = "-1"
- });
- }
- }
- public ActionResult Login()
- {
- return View();
- }
- public RedirectResult Logout()
- {
- Session.Clear();
- return Redirect("/Home?detecting=0");
- }
- private bool Check(string response)
- {
- //string Response = HttpContext.Current.Request.QueryString["g-recaptcha-response"];//Getting Response String Append to Post Method
- bool Valid = false;
- //Request to Google Server
- HttpWebRequest req = (HttpWebRequest)WebRequest.Create
- (" https://www.google.com/recaptcha/api/siteverify?secret=" + CommonUtils.CaptchaSecretKey + "&response=" + response);
- try
- {
- //Google recaptcha Response
- using (WebResponse wResponse = req.GetResponse())
- {
- using (StreamReader readStream = new StreamReader(wResponse.GetResponseStream()))
- {
- string jsonResponse = readStream.ReadToEnd();
- JavaScriptSerializer js = new JavaScriptSerializer();
- MyObject data = js.Deserialize<MyObject>(jsonResponse);// Deserialize Json
- Valid = Convert.ToBoolean(data.success);
- }
- }
- return Valid;
- }
- catch (WebException ex)
- {
- throw ex;
- }
- }
- public class MyObject
- {
- public string success { get; set; }
- }
- }
- }
|