コード例 #1
0
ファイル: UserController.cs プロジェクト: swomack/iq_asp
        public ActionResult VerifyAccount(string id)
        {
            bool   Status  = false;
            string Message = "";

            using (SampleASPEntities db = new SampleASPEntities())
            {
                var v = db.Users.Where(a => a.Token == new Guid(id)).FirstOrDefault();

                if (v != null)
                {
                    Status       = true;
                    v.IsVerified = true;
                    db.SaveChanges();
                }
                else
                {
                    Message = "Invalid activation code!";
                }
            }

            ViewBag.Status  = Status;
            ViewBag.Message = Message;

            return(View());
        }
コード例 #2
0
ファイル: UserController.cs プロジェクト: swomack/iq_asp
        public ActionResult Registration([Bind(Exclude = "IsVerified, Token, IsLoggedin")] User user)
        {
            bool   Status  = false;
            String Message = "";

            if (ModelState.IsValid)
            {
                if (IsUserNameExist(user.Username))
                {
                    ModelState.AddModelError("UsernameExists", "You can not use this username, its already taken!");
                }
                else
                {
                    #region Generate Userid
                    user.Userid = Guid.NewGuid();
                    #endregion

                    #region Generate Token
                    user.Token = Guid.NewGuid();
                    #endregion

                    #region Passowrd Hashing
                    user.Password        = Crypto.Hash(user.Password);
                    user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword);
                    #endregion

                    user.IsVerified = false;
                    user.IsLoggedin = false;

                    #region Saving to Database
                    using (SampleASPEntities SampleASPDatabase = new SampleASPEntities())
                    {
                        user.IsVerified = true;
                        user.IsLoggedin = false;
                        SampleASPDatabase.Users.Add(user);
                        SampleASPDatabase.SaveChanges();

                        #region Send Email Verification code
                        SendEmailVerificationCode(user.Email, user.Token);
                        Message = "Account created, verification code sent.";
                        #endregion

                        Status = true;
                    }
                    #endregion
                }
            }
            else
            {
                Message = "Invalid Message";
            }

            ViewBag.Status  = Status;
            ViewBag.Message = Message;

            return(View(user));
        }