Пример #1
0
        public virtual ActionResult Index(SignInViewModel viewModel, string returnUrl)
        {
            if (viewModel.RegisterViewModel == null)
                viewModel.RegisterViewModel = new SignInRegisterViewModel { ReturnUrl = returnUrl };
            viewModel.ReturnUrl = returnUrl;

            if (!ModelState.IsValid)
                return View(viewModel);

            var pwd = Util.GetMD5Hash(viewModel.Password.Trim());

            using (var context = new TTTEntities())
            {
                var user = 
                    context.tblaccesses
                        .SingleOrDefault(a => a.Email == viewModel.Email && 
                                              a.Password == pwd && 
                                              a.Active);

                if (user == null)
                {
                    ModelState.AddModelError("LoginForm", "Invalid Email/Password.");
                    return View(viewModel);
                }

                if (!user.ConfirmedEmail)
                {
                    var verifyEmailModel = new VerifyEmailViewModel { User = user, AfterLogin = true };
                    return View(MVC.SignIn.Views.VerifyEmail, verifyEmailModel);
                }

                Util.SessionAccess = user;
                FormsAuthentication.SetAuthCookie(viewModel.Email, false);
            }

            LinkToAccount();

            return RedirectToLocal(viewModel.ReturnUrl);
        }
Пример #2
0
        public virtual ActionResult Register(SignInViewModel viewModel)
        {
            var model = viewModel.RegisterViewModel;
            tblaccess user;

            using (var context = new TTTEntities())
            {
                user = context.tblaccesses.Where(a => a.Email == model.Email && a.Active).SingleOrDefault();

                if (user == null)
                {
                    user = new tblaccess
                    {
                        Active = true,
                        CreateDT = DateTime.Now,
                        Email = model.Email,
                        Password = Util.GetMD5Hash(model.Password),
                        FirstName = model.FirstName,
                        LastName = model.LastName,
                        EmailToken = Guid.NewGuid().ToString()
                    };

                    context.tblaccesses.Add(user);
                    context.SaveChanges();

                    var verifyEmailModel = new VerifyEmailViewModel { User = user, AfterRegistration = true };
                    return View(MVC.SignIn.Views.VerifyEmail, verifyEmailModel);
                }
                else
                {
                    ModelState.Clear();
                    ModelState.AddModelError("RegisterForm", "Email already exists. Please enter a different Email.");
                    return View(Views.Index, viewModel);
                }
            }
        }
Пример #3
0
        public virtual ActionResult VerifyEmail(VerifyEmailViewModel viewModel)
        {
            using (var context = new TTTEntities())
            {
                var user = context.tblaccesses.Where(a => a.ID == viewModel.User.ID).Single();

                SendEmailVerification(user);

                ViewBag.Email = user.Email;
            }

            return View(MVC.SignIn.Views.VerifyEmailSent);
        }
Пример #4
0
        public virtual ActionResult FacebookLoginCallback(string returnUrl)
        {
            AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("FacebookLoginCallback", new { returnUrl = returnUrl }));
            if (!result.IsSuccessful)
            {
                return RedirectToAction("FacebookLoginFailure");
            }

            var email = result.UserName;
            var accessToken = result.ExtraData["accesstoken"];
            var fbID = result.ExtraData["id"];
            var name = result.ExtraData["name"];
            //var gender = result.ExtraData.ContainsKey("gender") ? result.ExtraData["gender"] : "";
            //Session["FB_AccessToken"] = accessToken;
            tblaccess user = null;

            using (var context = new TTTEntities())
            {
                user = context.tblaccesses.Where(a => a.FacebookID == fbID && a.Active).SingleOrDefault();

                if (user == null)
                {
                    user = new tblaccess
                    {
                        Active = true,
                        CreateDT = DateTime.Now,
                        Email = email,
                        FacebookAccessToken = accessToken,
                        FacebookID = fbID,
                        Password = "",
                        FirstName = name,
                        EmailToken = Guid.NewGuid().ToString()
                    };

                    context.tblaccesses.Add(user);
                    context.SaveChanges();

                    var verifyEmailModel = new VerifyEmailViewModel { User = user, AfterRegistration = true };
                    return View(MVC.SignIn.Views.VerifyEmail, verifyEmailModel);
                }
                else
                {
                    if (user.ConfirmedEmail)
                    {
                        Util.SessionAccess = user;
                        FormsAuthentication.SetAuthCookie(user.Email, false);
                        LinkToAccount();
                    }
                    else
                    {
                        var verifyEmailModel = new VerifyEmailViewModel { User = user, AfterLogin = true };
                        return View(MVC.SignIn.Views.VerifyEmail, verifyEmailModel);
                    }                    
                }
            }

            return RedirectToLocal(returnUrl);
        }