Пример #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());
        }
Пример #2
0
        // Kullanıcı Şifresini Şifreleme Testi

        void sifreOlusturTest(string girisDeger, string cikisDeger)
        {
            Sifrele sifrele = new Sifrele();
            string  sifre;

            sifre = sifrele.SifreOlustur(girisDeger);
            Assert.AreEqual(cikisDeger, sifre);
        }
Пример #3
0
        //public static User Save(User gelen)
        //{
        //    string sifre = Sifrele.sifrele(gelen.Password_User);
        //    SqlConnection bag = DataHelp.baglan();
        //    IEnumerable<User> kullanici = bag.Query<User>(
        //      "SELECT * FROM [User] where Mail_User=@Mail And Password_User=@parola", new { Mail = gelen.Mail_User, parola = sifre });

        //    return kullanici.FirstOrDefault();

        //}

        public static User CheckUserPassword(string mailAd, string pass)
        {
            string sifreliPas = Sifrele.sifrele(pass);
            User   user       = GetByUsername(mailAd);

            //if (user == null)
            //    result = false;

            //if (user.Password_User != sifreliPas)
            ////    result = false;

            //return result;
            return(user);
        }
Пример #4
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());
        }