| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- using LotteryWebApp.Common;
- using LotteryWebApp.Extensions;
- using LotteryWebApp.Languages;
- using LotteryWebApp.Models;
- using LotteryWebApp.Service;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using System;
- using System.Globalization;
- namespace LotteryWebApp.Controllers
- {
- [AutoValidateAntiforgeryToken]
- public class ProfileController : BaseController
- {
- private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
- IConfiguration configuration;
- private readonly IWebHostEnvironment webHostEnvironment;
- APIFunctions api = new APIFunctions();
- public ProfileController(IConfiguration _configuration, IWebHostEnvironment hostEnvironment)
- {
- configuration = _configuration;
- webHostEnvironment = hostEnvironment;
- }
- public String GetParameter(String key)
- {
- return configuration.GetSection(key).Value;
- }
- public IActionResult Index()
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(Constants.SUB_DOMAIN) + "/Account/Login");
- }
- HttpContext.Session.SetComplexData("navigator", Constants.PROFILE_NAVIGATOR);
- ProfileViewModel model = new ProfileViewModel();
- try
- {
- model.channel = GetParameter(Constants.CHANNEL);
- // load msisdn
- String msisdn = HttpContext.Session.GetComplexData<String>("msisdn");
- String token = HttpContext.Session.GetComplexData<String>("token");
- Profile profile = HttpContext.Session.GetComplexData<Profile>("profile");
- if (profile == null)
- {
- // load profile
- UserGetProfileRequest request = new UserGetProfileRequest();
- request.users = msisdn;
- request.token = token;
- Profile profileGet = api.UserLoadProfileApi(configuration, request);
- if (profileGet.status == Code.SESSION_EXPIRED)
- {
- return Redirect(GetParameter(Constants.SUB_DOMAIN) + "/Account/Login");
- }
- model.profile = profileGet;
- HttpContext.Session.SetComplexData("profile", profileGet);
- }
- else
- {
- model.profile = profile;
- }
- UserStatus userStatus = HttpContext.Session.GetComplexData<UserStatus>("userStatus");
- if (profile == null)
- {
- // load profile
- UserStatusRequest userStatusRequest = new UserStatusRequest();
- userStatusRequest.users = msisdn;
- userStatusRequest.token = token;
- UserStatus userStatusResponse = api.GetUserStatusApi(configuration, userStatusRequest);
- if (userStatusResponse.status == Code.SESSION_EXPIRED)
- {
- return Redirect(GetParameter(Constants.SUB_DOMAIN) + "/Account/Login");
- }
- model.userStatus = userStatusResponse;
- HttpContext.Session.SetComplexData("userStatus", userStatusResponse);
- }
- else
- {
- model.userStatus = userStatus;
- }
- }
- catch (Exception ex)
- {
- log.Error(ex);
- }
- return View(model);
- }
- public IActionResult ChangePassword(string code)
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(Constants.SUB_DOMAIN) + "/Account/Login");
- }
- ProfileChangePassword_ViewModel model = new ProfileChangePassword_ViewModel();
- model.code = code;
- return View(model);
- }
- [ValidateAntiForgeryToken]
- public JsonResult ChangePassword_Action(string oldpass, string newpass, string confirmpass)
- {
- try
- {
- String msisdn = HttpContext.Session.GetComplexData<String>("msisdn");
- String token = HttpContext.Session.GetComplexData<String>("token");
- if (newpass != null && newpass != "" && newpass == confirmpass)
- {
- // update
- RegisterRequest registerRequest = new RegisterRequest();
- registerRequest.Msisdn = msisdn;
- registerRequest.Users = msisdn;
- registerRequest.pass = oldpass;
- registerRequest.Passnew = newpass;
- registerRequest.token = token;
- RegisterResponse updateProfile = api.UserChangePasswordApi(configuration, registerRequest);
- return Json(new
- {
- code = int.Parse(updateProfile.status),
- message = GetLangFromCode(updateProfile.status),
- });
- }
- else
- {
- return Json(new
- {
- code = Code.FAILURE,
- message = Lang.new_pass_error
- });
- }
- }
- catch (Exception ex)
- {
- log.Error(ex);
- }
- return Json(new
- {
- code = Code.FAILURE,
- message = Lang.error_happened
- });
- }
- public IActionResult ProfileInfo(String code)
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(Constants.SUB_DOMAIN) + "/Account/Login");
- }
- ProfileProfileInfo_ViewModel model = new ProfileProfileInfo_ViewModel();
- try
- {
- model.code = code;
- Profile profile = HttpContext.Session.GetComplexData<Profile>("profile");
- model.profile = profile;
- }
- catch (Exception ex)
- {
- log.Error(ex);
- }
- return View(model);
- }
- [ValidateAntiForgeryToken]
- public JsonResult ProfileInfoUpdate_Action(string fullname, string birthday)
- {
- try
- {
- String msisdn = HttpContext.Session.GetComplexData<String>("msisdn");
- String token = HttpContext.Session.GetComplexData<String>("token");
- Profile profile = HttpContext.Session.GetComplexData<Profile>("profile");
- String birthdayFormat = DateTime.ParseExact(birthday, "yyyy-MM-dd", CultureInfo.InvariantCulture).ToString("dd/MM/yyyy");
- // update
- UserUpdateProfileRequest userUpdateProfileRequest = new UserUpdateProfileRequest();
- userUpdateProfileRequest.users = msisdn;
- userUpdateProfileRequest.fullName = fullname;
- userUpdateProfileRequest.birthday = birthdayFormat;
- userUpdateProfileRequest.picture = profile.realPicture;
- userUpdateProfileRequest.token = token;
- UserUpdateProfileResponse updateProfile = api.UserUpdateProfileApi(configuration, userUpdateProfileRequest);
- if (updateProfile.status == Code.SUCCESS)
- {
- // update profile
- profile.fullName = fullname;
- profile.birthday = birthdayFormat;
- HttpContext.Session.SetComplexData("profile", profile);
- }
- return Json(new
- {
- code = int.Parse(updateProfile.status),
- message = GetLangFromCode(updateProfile.status)
- });
- }
- catch (Exception ex)
- {
- log.Error(ex);
- }
- return Json(new
- {
- code = Code.FAILURE,
- message = Lang.error_happened
- });
- }
- public IActionResult HowToPlay(string termType)
- {
- if (!CheckAuthToken())
- {
- return Redirect(GetParameter(Constants.SUB_DOMAIN) + "/Account/Login");
- }
- ProfileHowToPlay_ViewModel model = new ProfileHowToPlay_ViewModel();
- model.termType = termType != null ? termType : Constants.GameGroup.Singapore;
- return View(model);
- }
- }
- }
|