Esempio n. 1
0
        //[ValidateAntiForgeryToken]
        public ActionResult Login([Bind(Include = "Id,Email,Sifre,Onaysifre")] Users kullanici)
        {
            Session["kullanici"] = null;
            if (ModelState.IsValid)
            {
                sipahiibEntities sipahiibEntity = new sipahiibEntities();

                var      firstLogin = sipahiibEntity.Users.FirstOrDefault(m => m.Email == kullanici.Email);
                String[] parts      = kullanici.Email.Split(new[] { '@' });

                if (firstLogin == null && kullanici.Email != null)
                {
                    FormsAuthentication.SetAuthCookie(kullanici.Email, false);

                    kullanici.OnaySifre  = kullanici.Sifre;
                    Session["kullanici"] = parts[0];

                    sipahiibEntity.Users.Add(kullanici);
                    sipahiibEntity.SaveChanges();
                }

                var validKullanici = sipahiibEntity.Users.FirstOrDefault(m => m.Email == kullanici.Email && m.Sifre == kullanici.Sifre);

                if (validKullanici != null)
                {
                    Session["kullanici"] = parts[0];
                    FormsAuthentication.SetAuthCookie(validKullanici.Email, false);
                }
                else
                {
                    ViewBag.Invalid = "Geçersiz kullanıcı adı veya şifre";
                    return(View());
                }

                return(RedirectToAction("Index", "Home"));
            }

            return(View(kullanici));
        }
Esempio n. 2
0
        public ActionResult PasswordRemember(Users e)
        {
            if (e.Email == null)
            {
                ViewBag.Remember = "Email girmeniz gerekmektedir";
            }
            else
            {
                sipahiibEntities sipahiibEntity = new sipahiibEntities();

                var existingEmail = sipahiibEntity.Users.FirstOrDefault(m => m.Email == e.Email);
                if (existingEmail != null && existingEmail.Email == e.Email)
                {
                    StringBuilder message = new StringBuilder();
                    MailAddress   fromAdd = new MailAddress("*****@*****.**");

                    message.AppendLine("Şifreniz: " + existingEmail.Sifre);

                    MailMessage mail = new MailMessage();

                    mail.From = fromAdd;
                    mail.To.Add(existingEmail.Email.ToString());
                    mail.Subject    = "Kayıtlı Şifreniz";
                    mail.Body       = message.ToString();
                    mail.IsBodyHtml = true;

                    SendMail(mail);
                }
                else
                {
                    ViewBag.Remember = "Kayıtlı olmayan bir email girdiniz";
                }
            }
            ModelState.Clear();
            return(View());
        }