using NEducation.Content.Texts; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using NEducation.Code; using System.Configuration; namespace NEducation.Controllers { public class HttpController : Controller { // GET: Http public ActionResult Index() { return View(); } [ValidateAntiForgeryToken] public JsonResult Signup(String phoneNumber) { String msisdn = UtilsController.validateMsisdn(phoneNumber); if (msisdn != "") { UserInfoRequest user = new UserInfoRequest(); user.users = msisdn; user.msisdn = msisdn; user.command = "REGIST"; user.channel = "WEB"; String rs = UtilsController.SendPost(user, Session.SessionID, UtilsController.WsType.UsersRegister); UserActionResult res = new UserActionResult(rs); if (res.status == "0") { // login success --> store session Session["msisdn"] = msisdn; // get profile GetUserProfileReq req = new GetUserProfileReq(); req.users = msisdn; rs = UtilsController.SendPost(req, Session.SessionID, UtilsController.WsType.UsersGetProfile); UserProfile profile = new UserProfile(rs); Session["profile"] = profile; // success return Json(new { error_code = res.status, error_content = res.message, msisdn = msisdn.Substring(UtilsController.CountryCode.Length), href = "/Home/MyProfile" }); } else { // sign up fail return Json(new { error_code = res.status, error_content = UtilsController.ErrorContent(res.status), msisdn = msisdn.Substring(UtilsController.CountryCode.Length) }); } } else { return Json(new { error_code = "-1", error_content = Lang.InvalidMsisdn }); } } [ValidateAntiForgeryToken] public JsonResult Login(String phoneNumber, String password) { try { System.Diagnostics.Debug.WriteLine("before " + phoneNumber); String msisdn = UtilsController.validateMsisdn(phoneNumber); System.Diagnostics.Debug.WriteLine("after " + msisdn); if (msisdn != "" && msisdn != null) { UserInfoRequest user = new UserInfoRequest(); user.users = msisdn; user.msisdn = msisdn; user.pass = password; user.command = "LOGIN"; user.channel = "WEB"; String rs = UtilsController.SendPost(user, Session.SessionID, UtilsController.WsType.UsersRegister); UserActionResult res = new UserActionResult(rs); if (res.status == "0") { // login success --> store session Session["msisdn"] = msisdn; // get profile ReloadProfileInfo(); // get sub ReloadSubInfo(); System.Diagnostics.Debug.WriteLine(Session); UserProfile profile = Session["profile"] as UserProfile; return Json(new { error_code = res.status, error_content = res.message, msisdn = msisdn.Substring(UtilsController.CountryCode.Length), //href = (profile == null || profile.fullName == null || profile.fullName == "" || profile.picture == null || profile.picture == "") ? // "/Home/AccountProfile" : "/Home/Profiles" href = "/Home/AccountProfile" }); } else { return Json(new { error_code = res.status, //error_content = CommonController.ErrorContent(res.status), error_content = res.message, msisdn = msisdn.Substring(UtilsController.CountryCode.Length) }); } } else { return Json(new { error_code = "-1", error_content = Lang.InvalidMsisdn }); } } catch (Exception ex) { return Json(new { error_code = "-2", error_content = ex.Message }); ; } } public void ReloadProfileInfo() { String msisdn = Session["msisdn"] as String; if (msisdn != null) { GetUserProfileReq req = new GetUserProfileReq(); req.users = msisdn; String rs = UtilsController.SendPost(req, Session.SessionID, UtilsController.WsType.UsersGetProfile); UserProfile profile = new UserProfile(rs); System.Diagnostics.Debug.WriteLine("profile: " + profile); Session["profile"] = profile; } } public void ReloadSubInfo() { String msisdn = Session["msisdn"] as String; if (msisdn != null) { GetSubReq reqSub = new GetSubReq(); reqSub.msisdn = msisdn; String rs = UtilsController.SendPost(reqSub, Session.SessionID, UtilsController.WsType.SubGetListsubServiceCode); GetSubRes resSub = new GetSubRes(rs); Session["subInfo"] = resSub.listSubServiceCode; } } } }