コード例 #1
0
        public ActionResult VerifyAccount(String id) // from id i will get the activation code fromn the link which we have sent to the user email id this is means activation code
        {
            bool status = false;

            using (Shopping_Store_DataBaseEntities sd = new Shopping_Store_DataBaseEntities())
            {
                sd.Configuration.ValidateOnSaveEnabled = false; // this line i have added to avoid confirm password doesnot match issue

                var v = sd.Users.Where(a => a.ActivationKey == new Guid(id)).FirstOrDefault();

                // if link is valid then v is not null
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    sd.SaveChanges();
                    status = true;
                }
                else
                {
                    ViewBag.message = "Invalid request";
                }
            }
            ViewBag.Status = status;

            return(View());
        }
コード例 #2
0
 public bool IsEmailExist(String emailId)
 {
     using (Shopping_Store_DataBaseEntities sd = new Shopping_Store_DataBaseEntities())
     {
         var v = sd.Users.FirstOrDefault(a => a.EmailId == emailId);
         return(v != null);
     }
 }
コード例 #3
0
        public ActionResult AdminView(string username)
        {
            if (Session["username"] == null)
            {
                return(RedirectToAction("LoginAdmin", "Admin"));
            }

            Shopping_Store_DataBaseEntities db = new Shopping_Store_DataBaseEntities();

            ViewBag.username = Session["username"];
            return(View(db.Categories.ToList()));
        }
コード例 #4
0
        public ActionResult LoginAdmin(UserLogin login, string returnUrl)
        {
            //string message = "";
            //using (Shopping_Store_DataBaseEntities sd = new Shopping_Store_DataBaseEntities())
            //{
            //    var v = sd.Users.Where(a => a.EmailId == login.EmailId).FirstOrDefault();
            //    if (v != null)
            //    {
            //        if (string.Compare(Crypto.Hash(login.Password),v.Password)==0)
            //        {
            //            // if user has cehecked remember me option then save password for 1 year 525600 min= 1 year otherwise 20 minute
            //            int timeout = login.RememberMe ? 525600 : 20;
            //            var ticket=new FormsAuthenticationTicket(login.EmailId,login.RememberMe,timeout);
            //            string encrypted = FormsAuthentication.Encrypt(ticket);
            //            var cookie= new HttpCookie(FormsAuthentication.FormsCookieName,encrypted);
            //            cookie.Expires = DateTime.Now.AddMinutes(20);
            //            cookie.HttpOnly = true;
            //            Response.Cookies.Add(cookie);

            //            if (Url.IsLocalUrl(returnUrl))
            //            {
            //                return Redirect(returnUrl);
            //            }
            //            else
            //            {
            //                return RedirectToAction("Index", "Home");

            //            }

            //        }
            //        else
            //        {
            //            message = "Invalid credential provided";

            //        }

            //    }
            //    else
            //    {
            //        message = "Invalid credential provided";

            //    }
            //}
            //    ViewBag.Message = message;


            Shopping_Store_DataBaseEntities db = new Shopping_Store_DataBaseEntities();
            var v = db.Users.SingleOrDefault(x => x.EmailId == login.EmailId);

            //        if (string.Compare(Crypto.Hash(login.Password),v.Password)==0)

            if (v != null && String.CompareOrdinal(Crypto.Hash(login.Password), v.Password) == 0)
            {
                ViewBag.message   = "Login";
                ViewBag.triedOnce = "yes";
                System.Web.HttpContext.Current.Session["username"] = v.EmailId;
                return(RedirectToAction("AdminView", "Admin", new { username = login.EmailId }));
            }


            ViewBag.triedOnce = "yes";
            return(View());
        }
コード例 #5
0
        //for automatic binding we use bind exclude
        public ActionResult Signup([Bind(Exclude = "IsEmailVerified,ActivationKey")] User user)
        {
            bool   status = false;
            string message;

            //model validation
            if (ModelState.IsValid)
            {
                #region //email is already exist or validation of email

                var isExist = IsEmailExist(user.EmailId);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(user));
                }

                #endregion


                #region  generate activation key

                user.ActivationKey = Guid.NewGuid();

                #endregion

                //password hashing for security (not saving password in our db and hash value is stored in our db)

                #region

                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword); //to avoid confirm password validation issues

                #endregion

                //to avoid validation again on save changes i use
                user.IsEmailVerified = false;

                #region save data in our database

                using (Shopping_Store_DataBaseEntities sd = new Shopping_Store_DataBaseEntities())
                {
                    user.IsAdmin = false;
                    sd.Users.Add(user);
                    sd.SaveChanges();

                    //send email to user
                    SendVeificationLinkEmail(user.EmailId, user.ActivationKey.ToString());
                    message =
                        "Registration is sucessfully done!.Account activation link has been send to your email id " +
                        user.EmailId;
                    status = true;
                }

                #endregion
            }
            else
            {
                message = "Invalid request";
            }



            ViewBag.Message = message;
            ViewBag.Status  = status;



            return(View(user));
        }