Пример #1
0
        public ActionResult Register(RegisterInfoModel model)
        {
            var googleCaptchaBAL = new GoogleCaptchaBAL();

            if (googleCaptchaBAL.Authenticate(Request["g-recaptcha-response"]) && ModelState.IsValid)
            {
                try
                {
                    // Tách lấy username của người dùng
                    var userName = model.UserEmail.Split('@')[0];

                    // Kiểm tra thông tin người dùng này đã tồn tại chưa
                    // Nếu tồn tại rồi thì đánh chỉ số cho người dùng đó
                    var id = WebSecurity.GetUserId(userName);
                    if (id > 0)
                    {
                        var indexUser = (new Random()).Next(1, 10000);
                        userName += indexUser.ToString();
                    }
                    model.UserName = userName;

                    // Tạo tài khoản
                    var tokenKey = WebSecurity.CreateUserAndAccount(model.UserName, model.Password, null, true);
                    // Bổ sung thông tin tài khoản tài khoản
                    var userInformationBAL = new UserInformationBAL();
                    userInformationBAL.Create(new UserInformation()
                    {
                        FirstName = model.FirstName,
                        LastName  = model.LastName,
                        UserEmail = model.UserEmail,
                        UserName  = model.UserName,
                        CityCode  = model.CityCode
                    });
                    //Gui mail yeu cau kich hoat tai khoan
                    var mailConfirmAccountBAL = new MailConfirmAccountBAL();
                    mailConfirmAccountBAL.SendConfirmMail(model.UserEmail, model.UserName, tokenKey);
                    return(RedirectToAction("ActivateNotification", "Account", new { username = model.UserEmail }));
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // Get list of city
            var cityBAL = new CityBAL();

            model.LstCity = cityBAL.GetAll();
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #2
0
        public ActionResult Edit()
        {
            var userName = WebSecurity.CurrentUserName;
            //Lấy thông tin của user
            var userInfoBAL = new UserInformationBAL();

            var model = userInfoBAL.GetByUserName(userName);

            return(View(new UserInformationForEditModel()
            {
                UserName = model.UserName,
                FirstName = model.FirstName,
                LastName = model.LastName,
                UserEmail = model.UserEmail,
                CityCode = model.CityCode,
                Status = model.Status
            }));
        }
Пример #3
0
 public ActionResult IsAuthenticated()
 {
     if (WebSecurity.IsAuthenticated)
     {
         var userInfo = new SignnedInUserModel();
         userInfo.UserName   = WebSecurity.CurrentUserName;
         userInfo.IsLoggedIn = WebSecurity.IsAuthenticated;
         var userInformationBL = new UserInformationBAL();
         var currUserInfo      = userInformationBL.GetByUserName(userInfo.UserName);
         if (currUserInfo != null)
         {
             userInfo.UserEmail = currUserInfo.UserEmail;
             userInfo.FirstName = currUserInfo.FirstName;
             userInfo.LastName  = currUserInfo.LastName;
         }
         return(PartialView("_AuthenticatedPartial", userInfo));
     }
     else
     {
         return(PartialView("_AnonymousPartial"));
     }
 }