Example #1
0
        public async Task <ActionResult> ExternalLoginCallback(string returnUrl)
        {
            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

            if (loginInfo == null)
            {
                return(RedirectToAction("Login"));
            }

            // Sign in the user with this external login provider if the user already has a login
            var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent : false);

            switch (result)
            {
            case SignInStatus.Success:
                //return RedirectToLocal(returnUrl);
                string             emailid = loginInfo.Email;
                DBConnection       db      = new DBConnection();
                var                id      = db.vendor.Where(m => m.VendorEmail == emailid).Select(m => m.VendorId).FirstOrDefault();
                int                vid     = Convert.ToInt32(id);
                VendorLogInOutTime vliot   = new VendorLogInOutTime();
                vliot.LogInTime  = DateTime.Now;
                vliot.VendorId   = vid;
                vliot.LogOutTime = null;
                db.loginouttime.Add(vliot);
                db.SaveChanges();

                //Authentication and authorization.
                FormsAuthentication.SetAuthCookie(emailid, false);
                string Roles           = db.userrole.Where(x => x.VendorId == id).Select(x => x.RoleName).FirstOrDefault();
                var    authTicket      = new FormsAuthenticationTicket(1, emailid, DateTime.Now, DateTime.Now.AddMinutes(60), false, Roles);
                string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                var    authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                HttpContext.Response.Cookies.Add(authCookie);

                return(RedirectToAction("Index", "VendorAccess"));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false }));

            case SignInStatus.Failure:
            default:
                // If the user does not have an account, then prompt the user to create an account
                ViewBag.ReturnUrl     = returnUrl;
                ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
                return(View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel {
                    Email = loginInfo.Email
                }));
            }
        }
Example #2
0
        public async Task <ActionResult> vendorLogin(vendorViewLogin vvl)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(vvl));
                }

                AdminLogin admin = new AdminLogin();
                admin = db.adminlog.Where(x => x.EmailAddress == vvl.VendorEmail && (x.Passkey == vvl.VendorPassword)).FirstOrDefault();
                if (admin != null)
                {
                    //Session["superid"] = vvl.VendorEmail;
                    //Session["EmailId"] = vvl.VendorEmail;
                    //ViewBag.messg = vvl.VendorEmail;
                    FormsAuthentication.SetAuthCookie(vvl.VendorEmail, false);
                    string Roles           = "admin";
                    var    authTicket      = new FormsAuthenticationTicket(1, admin.EmailAddress, DateTime.Now, DateTime.Now.AddMinutes(30), false, Roles);
                    string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                    var    authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                    HttpContext.Response.Cookies.Add(authCookie);
                    return(RedirectToAction("AdminPortal", "SuperAdmin"));
                }
                else
                {
                    string      q      = vvl.VendorPassword;
                    string      pass   = Encrypt_Password(q);
                    VendorModel vendor = new VendorModel();
                    vendor = db.vendor.Where(m => m.VendorEmail == vvl.VendorEmail && (m.VendorPassword == pass)).FirstOrDefault();
                    if (vendor != null)
                    {
                        var id  = db.vendor.Where(m => m.VendorEmail == vvl.VendorEmail).Select(m => m.VendorId).FirstOrDefault();
                        int vid = Convert.ToInt32(id);
                        //Session["Adminid"] = vid;
                        //Session["EmailId"] = vvl.VendorEmail;
                        VendorLogInOutTime vliot = new VendorLogInOutTime();
                        vliot.LogInTime  = DateTime.Now;
                        vliot.VendorId   = vid;
                        vliot.LogOutTime = null;
                        db.loginouttime.Add(vliot);
                        var a = db.vendor.Where(m => m.VendorEmail == vvl.VendorEmail).FirstOrDefault();
                        a.DataCompleted = true;
                        var b = db.businessdetails.Where(x => x.VendorId == id).FirstOrDefault();
                        b.DataCompleted = true;
                        db.SaveChanges();

                        string Roles = db.userrole.Where(x => x.VendorId == vid).Select(x => x.RoleName).FirstOrDefault();
                        FormsAuthentication.SetAuthCookie(vvl.VendorEmail, false);
                        var    authTicket      = new FormsAuthenticationTicket(1, vendor.VendorEmail, DateTime.Now, DateTime.Now.AddMinutes(20), false, Roles);
                        string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                        var    authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                        HttpContext.Response.Cookies.Add(authCookie);
                        return(RedirectToAction("Index", "VendorAccess"));
                    }
                    else
                    {
                        ViewBag.errorvalue = "Please enter valid Login Id and Password.";
                        return(View());
                    }
                }
            }
            catch (Exception e)
            {
                Response.Write("<script>alert('Please enter emailId and password')</script>");
                return(View());
            }
        }