Beispiel #1
0
        public ActionResult Register(Register register)
        {
            bool   status  = false;
            string message = "";

            if (ModelState.IsValid)
            {
                if (isExistUser(register.email))
                {
                    message         = "bu mail var";
                    ViewBag.message = message;
                    return(View());
                }

                user user = new user();
                user.email = register.email;

                user.password       = Sifrele.Hash(register.password);
                user.rePassword     = Sifrele.Hash(register.comfirmPassword);
                user.activationCode = Guid.NewGuid().ToString();
                user.roleId         = 2;
                //oluşturulan kullanıcı mail doğrulama başlangıç olsun.
                user.isMailVerified = false;
                user.createdDate    = DateTime.Now;
                repoUser.Save(user);
                SendVerificationLinkEmail(user.email, user.activationCode);
                message         = "kayıt ok" + user.email + "adrese bakınız";
                status          = true;
                ViewBag.message = message;
                ViewBag.status  = status;
            }
            return(View());
        }
Beispiel #2
0
        public ActionResult Login(Login login, string ReturnUrl)
        {
            string message = "";
            int    sayac   = 0;
            bool   status  = false;

            if (ModelState.IsValid)
            {
                user user = repoUser.GetAll().Where(x => x.email == login.email).FirstOrDefault();
                if (user == null)
                {//881118
                    message         = "Email kaydı bulunamadı";
                    ViewBag.message = message;
                    ViewBag.status  = status;
                    return(View());
                }

                bool verify = user.isMailVerified ?? false;
                if (!verify)
                {
                    message         = "email doğrulama yapmadınız";
                    ViewBag.message = message;
                    ViewBag.status  = status;
                    sayac++;
                    user.loginAttempt = sayac;
                    repoUser.Update(user);
                }
                if (user.isActive == false)
                {
                    sayac++;
                    message           = "Hesabınız geçici olarak kapatıldı";
                    ViewBag.status    = status;
                    user.loginAttempt = sayac;
                    repoUser.Update(user);
                }
                login.password = Sifrele.Hash(login.password);
                //şifre eşleşiyorsa
                if (string.Compare(login.password, user.password) == 0)
                {
                    user.loginTime    = DateTime.Now;
                    user.loginAttempt = sayac;
                    repoUser.Update(user);
                    Session["username"] = user.email;
                    int timeOut = login.rememberMe ? 60 : 10;
                    //form hatırla
                    var    ticket    = new FormsAuthenticationTicket(login.email, login.rememberMe, timeOut);
                    string encrypted = FormsAuthentication.Encrypt(ticket);
                    var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                    cookie.Expires  = DateTime.Now.AddMinutes(timeOut);
                    cookie.HttpOnly = true;

                    FormsAuthentication.SetAuthCookie("username", login.rememberMe);
                    Response.Cookies.Add(cookie);

                    if (user.roleId == 1)
                    {
                        return(Redirect("~/Panel/Category"));
                    }
                    //return Url yerel bir url mi
                    if (Url.IsLocalUrl(ReturnUrl))
                    {
                        return(Redirect(ReturnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Shop"));
                    }
                }


                else
                {
                    sayac++;
                    user.loginAttempt = sayac;
                    repoUser.Update(user);
                    message = "Parolayı hatalı girdiniz!!";
                }
            }


            return(View());
        }