예제 #1
0
 public ActionResult GetUserInfo()
 {
     BaseModel userModel = new UserModel();
     int returnCode = this._userBl.SelectDataByID(base.UserId, out userModel);
     return PartialView("_UserInfoPartial", userModel);
 }
예제 #2
0
        public ActionResult Login(UserModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            //Encrypt data
            EncryptionContext encryption = new EncryptionContext(new SHA256Encryption());
            model.Password = encryption.EncryptString(model.Password);
            model.Email = encryption.EncryptString(model.Email);

            //Login to the system
            BaseModel resultModel = new UserModel();
            int returnCode = this._userBl.Login(model.Email, model.Password, out resultModel);

            //If exception occured
            if (returnCode != CommonData.ReturnCode.Succeed)
            {
                string message = ExceptionProcess.Instance.GetErrorMessage(returnCode);
                ModelState.AddModelError("", message);
                return View(model);
            }
            else
            {
                //If login failed
                if (resultModel == null)
                {
                    string message = new Message("COM_MSG_USER_NAME_PASSWORD_NOT_VALID").MessageText;
                    ModelState.AddModelError("", message);
                    return View(model);
                }
                //If login success
                else
                {
                    UserModel userModel = resultModel as UserModel;
                    //Save session
					ConfigSession(userModel);

                    //Save cookie
                    if (model.RememberMe)
                    {
                        HttpCookie cookie = new HttpCookie(CommonKey.conket);
                        cookie.Values.Add(CommonKey.ID, userModel.ID.ToString());
                        cookie.Expires = DateTime.Now.AddDays(15);
                        Response.Cookies.Add(cookie);
                    }

                    //Redirect to other page
                    if (CommonMethod.IsNullOrEmpty(returnUrl))
                    {
                        return RedirectToAction("Index", "Home", new { @area = "UserPage" });
                    }
                    else
                    {
                        return RedirectToLocal(returnUrl);
                    }
                }
            }
        }
예제 #3
0
 public ActionResult Setting()
 {
     SettingModel settingModel = new SettingModel();
     BaseModel userModel = new UserModel();
     int returnCode = _userBl.SelectDataByID(base.UserId, out userModel);
     if (userModel != null)
     {
         settingModel.SoundEffect = ((UserModel)userModel).SoundEffect == CommonData.Status.Enable ? true : false;
         settingModel.VocaPerLearn = ((UserModel)userModel).VocaPerLearn;
         settingModel.VocaPerReview = ((UserModel)userModel).VocaPerReview;
     }
     return View("Setting", settingModel);
 }
예제 #4
0
		/// <summary>
		/// Config session
		/// </summary>
		/// <param name="user"></param>
		private void ConfigSession(UserModel user = null)
		{
			if (CommonMethod.IsNullOrEmpty(user.ID))
			{
				Session[CommonKey.ID] = CommonData.StringEmpty;
				Session[CommonKey.UserName] = CommonData.StringEmpty;
				Session[CommonKey.Email] = CommonData.StringEmpty;
				Session[CommonKey.DisplayName] = CommonData.StringEmpty;
				Session[CommonKey.IsAdmin] = CommonData.Status.Disable;
				Session[CommonKey.UrlImage] = CommonData.StringEmpty;

				Session[CommonKey.VocaPerLearn] = UserDefine.VocaPerLearn;
				Session[CommonKey.VocaPerReview] = UserDefine.VocaPerReview;
				Session[CommonKey.SoundEffect] = UserDefine.SoundEffect;
			}
			else
			{
				Session[CommonKey.ID] = user.ID;
				Session[CommonKey.UserName] = user.UserName;
				Session[CommonKey.Email] = user.Email;
				Session[CommonKey.DisplayName] = user.DisplayName;
				Session[CommonKey.IsAdmin] = user.IsAdmin;
				Session[CommonKey.UrlImage] = user.UrlImage;

				Session[CommonKey.VocaPerLearn] = user.VocaPerLearn;
				Session[CommonKey.VocaPerReview] = user.VocaPerReview;
				Session[CommonKey.SoundEffect] = user.SoundEffect;
			}
		}