| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704 |
- 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 System.Threading.Tasks;
- using Mzb_LuckyCall.Resources;
- using System.ServiceModel;
- using System.ServiceModel.Channels;
- namespace LuckyCallWebCore.Controllers
- {
- public class HomeController : BaseController
- {
- private ILog log = LogManager.GetLogger("HomeController");
- ServiceAPI.WsLuckyCallClient wsClient = new ServiceAPI.WsLuckyCallClient();
- public HomeController(IConfiguration _configuration, IWebHostEnvironment hostEnvironment) : base(_configuration, hostEnvironment)
- {
- // init
- }
- public async Task<IActionResult> Index()
- {
- var account = await IdentifyMsisdn();
- if (account == "NOT_FOUND")
- {
- //return Redirect("/Home/Guide");
- return Redirect("/Home/Login");
- }
- if (account == null)
- {
- //return Redirect("/Home/NotSupport");
- return Redirect("/Home/Login");
- }
- ReloadUserInfo(account);
- SetWsClient(ref wsClient, account);
- using (new OperationContextScope(wsClient.InnerChannel))
- {
- // Add a HTTP Header to an outgoing request
- HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
- requestMessage.Headers["lang"] = getCurrentLang();
- OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
- response res = wsClient.wsGetListWinner(wsUser, wsPassword, null, "3", "1", "1", "-1", "-1");
- if (res.listWinner != null && res.listWinner.Length > 0)
- {
- var lastMonthWinner = res.listWinner[0];
- lastMonthWinner.msisdn = HiddenMsisdn(lastMonthWinner.msisdn);
- HttpContext.Session.SetComplexData("lastMonthWinner", lastMonthWinner);
- }
- }
- return await Task.Run(() => View());
- // return View();
- }
- public IActionResult Login()
- {
- return View();
- }
- public IActionResult Logout()
- {
- try
- {
- ClearCache();
- //return Redirect("mytel://home");
- return Redirect("/Home/Login");
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Redirect("/Home/Error");
- }
- }
- [HttpPost]
- public IActionResult LogoutAction()
- {
- ClearCache();
- return Json(new
- {
- error = "0"
- });
- }
- public IActionResult NotSupport()
- {
- try
- {
- //ClearCache();
- return View();
- }
- catch (Exception ex)
- {
- log.Error("Exception " + ex);
- return Redirect("/Home/Error");
- }
- }
- private void ReloadUserInfo(String username)
- {
- // store session
- UserInfo userInfo = new UserInfo();
- userInfo.msisdn = username;
- userInfo.username = username;
- //userInfo.remain_spin = 3;
- SetWsClient(ref wsClient, username);
- // get sub info
- using (new OperationContextScope(wsClient.InnerChannel))
- {
- // Add a HTTP Header to an outgoing request
- HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
- requestMessage.Headers["lang"] = getCurrentLang();
- OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
- response resSub = wsClient.wsGetSubInfo(wsUser, wsPassword, username);
- userInfo.spinInfo = resSub.spinResult;
- userInfo.total_spin = userInfo.spinInfo.totalSpin;
- //
- if (resSub.listRegInfo != null && resSub.listRegInfo.Length > 0)
- {
- userInfo.regInfo = resSub.listRegInfo[0];
- userInfo.total_spin = userInfo.total_spin + userInfo.regInfo.remainQuestion;
- }
- // coin
- userInfo.userCoin = resSub.userCoin;
- // store
- HttpContext.Session.SetComplexData("userInfo", userInfo);
- }
- }
- public IActionResult LuckyDraw()
- {
- UserInfo userInfo = HttpContext.Session.GetComplexData<UserInfo>("userInfo");
- if (!CheckAuthToken() || userInfo == null)
- {
- return Redirect("mytel://home");
- }
- //if (userInfo.remain_spin == 0)
- //{
- // return Redirect("/Home/Prize");
- //}
- return View();
- }
- public async Task<IActionResult> UserPrize(String page)
- {
- String account = HttpContext.Session.GetString("account");
- UserInfo userInfo = HttpContext.Session.GetComplexData<UserInfo>("userInfo");
- if (!CheckAuthToken() || userInfo == null)
- {
- return Redirect("mytel://home");
- }
- // get user prize
- page = page ?? "1";
- String rowOnPage = configuration["pageSize"];
- SetWsClient(ref wsClient, account);
- using (new OperationContextScope(wsClient.InnerChannel))
- {
- // Add a HTTP Header to an outgoing request
- HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
- requestMessage.Headers["lang"] = getCurrentLang();
- OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
- response res = wsClient.wsGetListWinner(wsUser, wsPassword, userInfo.msisdn, "-1", page, rowOnPage, "-1", "1");
- // model
- LuckyWheelModel model = new LuckyWheelModel();
- model.page = page;
- model.pageSize = rowOnPage;
- model.totalPage = res.totalPage;
- model.listWinner = res.listWinner;
- return View(model);
- }
- }
- public async Task<IActionResult> WinnerList()
- {
- String account = HttpContext.Session.GetString("account");
- UserInfo userInfo = HttpContext.Session.GetComplexData<UserInfo>("userInfo");
- if (!CheckAuthToken() || userInfo == null)
- {
- return Redirect("mytel://home");
- }
- return await Task.Run(() => View());
- }
- [HttpPost]
- [ValidateAntiForgeryToken]
- public async Task<IActionResult> GetWinner(String page, String period)
- {
- String account = HttpContext.Session.GetString("account");
- UserInfo userInfo = HttpContext.Session.GetComplexData<UserInfo>("userInfo");
- if (!CheckAuthToken() || userInfo == null)
- {
- return Json(new
- {
- error = "-1",
- content = "Timeout",
- href = "mytel://home"
- });
- }
- // get user prize
- page = page ?? "1";
- String rowOnPage = configuration["pageSize"];
- SetWsClient(ref wsClient, account);
- using (new OperationContextScope(wsClient.InnerChannel))
- {
- // Add a HTTP Header to an outgoing request
- HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
- requestMessage.Headers["lang"] = getCurrentLang();
- OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
- response res = wsClient.wsGetListWinner(wsUser, wsPassword, null, period, page, rowOnPage, "-1", "-1");
- if (res.listWinner != null)
- {
- for (int i = 0; i < res.listWinner.Length; i++)
- {
- res.listWinner[i].msisdn = HiddenMsisdn(res.listWinner[i].msisdn);
- }
- }
- // model
- LuckyWheelModel model = new LuckyWheelModel();
- model.page = page;
- model.pageSize = rowOnPage;
- model.totalPage = res.totalPage;
- model.listWinner = res.listWinner;
- return PartialView("../Partial/_Winner", model);
- }
- }
- [HttpPost]
- [ValidateAntiForgeryToken]
- public IActionResult GetTopCoin()
- {
- String account = HttpContext.Session.GetString("account");
- UserInfo userInfo = HttpContext.Session.GetComplexData<UserInfo>("userInfo");
- if (!CheckAuthToken() || userInfo == null)
- {
- return Json(new
- {
- error = "-1",
- content = "Timeout",
- href = "mytel://home"
- });
- }
- // get user prize
- String rowOnPage = configuration["pageSize"];
- String size = "30";
- SetWsClient(ref wsClient, account);
- using (new OperationContextScope(wsClient.InnerChannel))
- {
- // Add a HTTP Header to an outgoing request
- HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
- requestMessage.Headers["lang"] = getCurrentLang();
- OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
- //
- response res = wsClient.wsGetTopCoin(wsUser, wsPassword, size);
- // model
- LuckyWheelModel model = new LuckyWheelModel();
- model.page = "1";
- model.pageSize = rowOnPage;
- if (res.listUserCoin != null)
- {
- model.totalPage = Convert.ToInt32(Math.Ceiling(res.listUserCoin.Length / decimal.Parse(rowOnPage)));
- for (int i = 0; i < res.listUserCoin.Length; i++)
- {
- res.listUserCoin[i].msisdn = HiddenMsisdn(res.listUserCoin[i].msisdn);
- }
- }
- model.listUserCoin = res.listUserCoin;
- response resRank = wsClient.wsGetUserRank(wsUser, wsPassword, userInfo.msisdn);
- model.userCoin = resRank.userCoin;
- return PartialView("../Partial/_TopCoin", model);
- }
- }
- public IActionResult Guide()
- {
- string currentLang = getCurrentLang();
- return View("Guide_" + currentLang);
- }
- public IActionResult Error()
- {
- return View();
- }
- [HttpPost]
- [ValidateAntiForgeryToken]
- public async Task<JsonResult> SpinAction()
- {
- String account = HttpContext.Session.GetString("account");
- UserInfo userInfo = HttpContext.Session.GetComplexData<UserInfo>("userInfo");
- if (!CheckAuthToken() || userInfo == null)
- {
- return Json(new
- {
- error = "-1",
- content = "Timeout",
- href = "mytel://home"
- });
- }
- if (userInfo.total_spin > 0)
- {
- SetWsClient(ref wsClient, account);
- using (new OperationContextScope(wsClient.InnerChannel))
- {
- // Add a HTTP Header to an outgoing request
- HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
- requestMessage.Headers["lang"] = getCurrentLang();
- OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
- response res = wsClient.wsDoSpin(wsUser, wsPassword, userInfo.msisdn, BaseController.channel);
- if (res.errorCode == "0")
- {
- // check prize add spin
- spinResultObj spinResult = res.spinResult;
- userInfo.spinInfo = spinResult;
- prizeObj prizeObj = MapPrize()[spinResult.prizeId];
- HttpContext.Session.SetComplexData("userInfo", userInfo);
- return Json(new
- {
- error = "0",
- content = res.content,
- prize = prizeObj,
- remainSpin = userInfo.spinInfo.remainSpin,
- totalSpin = userInfo.spinInfo.totalSpin,
- usedSpin = userInfo.spinInfo.usedSpin,
- totalCoin = userInfo.spinInfo.totalCoin,
- lastAction = prizeObj.actionCode
- });
- }
- else
- {
- return Json(new
- {
- error = res.errorCode,
- content = res.content
- });
- }
- }
- }
- else
- {
- return Json(new
- {
- error = "1",
- content = "Out of spin"
- });
- }
- }
- [HttpPost]
- [ValidateAntiForgeryToken]
- public async Task<JsonResult> RegisterOtp(String packageName)
- {
- String account = HttpContext.Session.GetString("account");
- UserInfo userInfo = HttpContext.Session.GetComplexData<UserInfo>("userInfo");
- if (!CheckAuthToken() || userInfo == null)
- {
- return Json(new
- {
- error = "-1",
- content = "Timeout",
- href = "mytel://home"
- });
- }
- SetWsClient(ref wsClient, account);
- using (new OperationContextScope(wsClient.InnerChannel))
- {
- // Add a HTTP Header to an outgoing request
- HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
- requestMessage.Headers["lang"] = getCurrentLang();
- OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
- response res = wsClient.wsRegisterSubOtp(wsUser, wsPassword, userInfo.msisdn, packageName, BaseController.channel);
- if (res.errorCode == "0" || res.errorCode == "100")
- {
- RequestOtp requestOtp = new RequestOtp();
- requestOtp.msisdn = userInfo.msisdn;
- requestOtp.packageName = packageName;
- requestOtp.requestId = res.resultCode;
- HttpContext.Session.SetComplexData("requestOtp", requestOtp);
- return Json(new
- {
- error = res.errorCode,
- content = res.content
- });
- }
- else
- {
- return Json(new
- {
- error = res.errorCode,
- content = res.content
- });
- }
- }
- }
- [HttpPost]
- [ValidateAntiForgeryToken]
- public async Task<JsonResult> RegisterConfirm(String otp)
- {
- String account = HttpContext.Session.GetString("account");
- UserInfo userInfo = HttpContext.Session.GetComplexData<UserInfo>("userInfo");
- RequestOtp requestOtp = HttpContext.Session.GetComplexData<RequestOtp>("requestOtp");
- if (!CheckAuthToken() || userInfo == null)
- {
- return Json(new
- {
- error = "-1",
- content = "Timeout",
- href = "mytel://home"
- });
- }
- SetWsClient(ref wsClient, account);
- using (new OperationContextScope(wsClient.InnerChannel))
- {
- // Add a HTTP Header to an outgoing request
- HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
- requestMessage.Headers["lang"] = getCurrentLang();
- OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
- response res = wsClient.wsRegisterSubConfirm(wsUser, wsPassword, userInfo.msisdn, requestOtp.packageName, requestOtp.requestId, otp, BaseController.channel);
- if (res.errorCode == "0")
- {
- return Json(new
- {
- error = "0",
- content = res.content
- });
- }
- else
- {
- return Json(new
- {
- error = res.errorCode,
- content = res.content
- });
- }
- }
- }
- [HttpPost]
- [ValidateAntiForgeryToken]
- public async Task<JsonResult> CancelConfirm(String packageName)
- {
- String account = HttpContext.Session.GetString("account");
- UserInfo userInfo = HttpContext.Session.GetComplexData<UserInfo>("userInfo");
- if (!CheckAuthToken() || userInfo == null)
- {
- return Json(new
- {
- error = "-1",
- content = "Timeout",
- href = "mytel://home"
- });
- }
- SetWsClient(ref wsClient, account);
- using (new OperationContextScope(wsClient.InnerChannel))
- {
- // Add a HTTP Header to an outgoing request
- HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
- requestMessage.Headers["lang"] = getCurrentLang();
- OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
- response res = wsClient.wsCancelSub(wsUser, wsPassword, account, packageName, channel);
- if (res.errorCode == "0")
- {
- return Json(new
- {
- error = res.errorCode,
- content = res.content
- });
- }
- else
- {
- return Json(new
- {
- error = res.errorCode,
- content = res.content
- });
- }
- }
- }
- [HttpPost]
- [ValidateAntiForgeryToken]
- public JsonResult LoginAction(String phoneNumber, string password)
- {
- String msisdn = 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;
- SetWsClient(ref wsClient, msisdn);
- using (new OperationContextScope(wsClient.InnerChannel))
- {
- // Add a HTTP Header to an outgoing request
- HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
- requestMessage.Headers["lang"] = getCurrentLang();
- OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
- ServiceAPI.response res = wsClient.wsLogin(wsUser, wsPassword, password, msisdn);
- if (res.errorCode == "0")
- {
- // login success --> store session
- CreateAuthToken(msisdn, null);
- ReloadUserInfo(msisdn);
- 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.LoginFailed
- });
- }
- }
- [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 = validateMsisdn(phoneNumber);
- if (msisdn != "")
- {
- SetWsClient(ref wsClient, msisdn);
- using (new OperationContextScope(wsClient.InnerChannel))
- {
- // Add a HTTP Header to an outgoing request
- HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
- requestMessage.Headers["lang"] = getCurrentLang();
- OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
- ServiceAPI.response res = wsClient.wsCreateAccount(wsUser, wsPassword, "", msisdn);
- if (res.errorCode == "0")
- {
- // signup success --> store session
- SetLastSignUp();
- CreateAuthToken(msisdn, null);
- ReloadUserInfo(msisdn);
- }
- 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)
- {
- CheckSessionRes checkSession = CheckSessionValid(ActionSession.Resetpass);
- if (checkSession.errorCode != "0")
- {
- return Json(new
- {
- error = checkSession.errorCode,
- content = checkSession.content
- });
- }
- String msisdn = validateMsisdn(phoneNumber);
- if (msisdn != "")
- {
- SetWsClient(ref wsClient, msisdn);
- using (new OperationContextScope(wsClient.InnerChannel))
- {
- // Add a HTTP Header to an outgoing request
- HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
- requestMessage.Headers["lang"] = getCurrentLang();
- OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
- 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
- });
- }
- }
- }
- }
|