Example #1
0
        public ActionResult Login(LoginFormViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }


            User user = userService.GetByLogin(model.Email, model.Password);
            if (user != null)
            {
                var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Email, user.Email), new Claim(ClaimTypes.Role, user.Role.Naziv) }, "ApplicationCookie");
                var ctx = Request.GetOwinContext();
                var authManager = ctx.Authentication;

                authManager.SignOut("ApplicationCookie");
                Session.Clear();

                authManager.SignIn(identity);

                Session.Add(Constants.User,user);
                return RedirectToAction("Index", "Home");
            }

            ModelState.AddModelError("", "Greska");
            return View();
        }
Example #2
0
        public ActionResult Login(string returnUrl = null)
        {
            var model = new LoginFormViewModel
            {
                ReturnUrl = returnUrl
            };

            return View("Login");
        }
Example #3
0
        public ActionResult SendMailRegistration(LoginFormViewModel wrap)
        {
            if (wrap.User.Password == null || wrap.User.ConfirmPassword == null)
                return View("Registration");

            if (wrap.User.Password.Equals(wrap.User.ConfirmPassword))
            {
                User user = Mapper.Map<UserViewModel, User>(wrap.User);
                user.RoleId = 2;

                try
                {
                    userService.Create(user);
                    userService.Save();
                }
                catch(Exception ex)
                {
                    return Json(new { Status = ex.StackTrace }, JsonRequestBehavior.AllowGet);
                }

                MailMessage mail = new MailMessage("*****@*****.**", user.Email);
                mail.Subject = "Registracija";
                mail.IsBodyHtml = true;

                //izmeniti!!!
                mail.Body = "http://localhost:1869/Account/ActivateUser?id=" + user.Id;

                SmtpClient smtp = new SmtpClient();
                smtp.Send(mail);


                return Json(new { Status = "Potvrdite na mejlu registraciju" }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { Status = "Sifre se ne poklapaju" }, JsonRequestBehavior.AllowGet);
            }
        }
Example #4
0
 public ActionResult Registration()
 {
     LoginFormViewModel lfvm = new LoginFormViewModel() { User = new UserViewModel() };
     return View("Registration");
 }