Exemple #1
0
        public ActionResult LogOff()
        {
            var test = User.Identity.Name;

            Teckraft.Data.Sql.InitiativeHubFinalEntities DbContext = new Teckraft.Data.Sql.InitiativeHubFinalEntities();
            var userprofile = DbContext.UserProfiles.FirstOrDefault(it => it.UserName.ToLower() == test.ToLower());
            var curSession  = DbContext.CurrentUserSessions.FirstOrDefault(it => it.UserId == userprofile.UserId);

            if (curSession != null)
            {
                DbContext.CurrentUserSessions.Remove(curSession);
            }
            DbContext.SaveChanges();
            Response.Cookies["ASP.NET_SessionId"].Value   = string.Empty;
            Response.Cookies["ASP.NET_SessionId"].Expires = DateTime.Now.AddDays(-2); //Delete the cookie
            //return Redirect("http://localhost:8052/account/LogOff?wa=wsignout1.0");
            WebSecurity.Logout();
            Session.Abandon();
            return(RedirectToAction("Login", "Account"));
        }
Exemple #2
0
        public DbActionResult <UserWiseColumnName> Post(UserWiseColumnName items)
        {
            var result = new DbActionResult <UserWiseColumnName>();

            try
            {
                var data = items;
                using (var dbcontext = new Teckraft.Data.Sql.InitiativeHubFinalEntities())
                {
                    // foreach (var i in data) {
                    var chap = dbcontext.ChapterMasters.FirstOrDefault(it => it.ChapterNameFromSystem == data.chapterName);
                    if (chap != null)
                    {
                        data.ChapterId = chap.Id;
                    }
                    var existingList = dbcontext.UserWiseColumnNames.FirstOrDefault(it => it.UserId == data.UserId && it.ChapterId == data.ChapterId);
                    if (existingList != null)
                    {
                        //dbcontext.UserWiseColumnNames.Remove(existingList);
                        existingList.ChapterId             = data.ChapterId;
                        existingList.UserId                = data.UserId;
                        existingList.chapternamedisplay    = data.chapternamedisplay;
                        existingList.chapterOwner          = data.chapterOwner;
                        existingList.ID_Category           = data.ID_Category;
                        existingList.id_comments           = data.id_comments;
                        existingList.id_data_load_date     = data.id_data_load_date;
                        existingList.id_dept               = data.id_dept;
                        existingList.ID_Issue_Detail1      = data.ID_Issue_Detail1;
                        existingList.id_location           = data.id_location;
                        existingList.ID_Logged_Date        = data.ID_Logged_Date;
                        existingList.id_pending_with_email = data.id_pending_with_email;
                        existingList.id_pending_with_name  = data.id_pending_with_name;
                        existingList.id_reported_by_email  = data.id_reported_by_email;
                        existingList.id_reported_by_name   = data.id_reported_by_name;
                        existingList.id_request            = data.id_request;
                        existingList.id_status             = data.id_status;
                        existingList.ID_Target_Date        = data.ID_Target_Date;
                        existingList.id_tat_status         = data.id_tat_status;
                        existingList.pendingSince          = data.pendingSince;
                        existingList.title  = data.title;
                        existingList.UserId = _userservice.GetCurrentUser().Id;
                        existingList.RUB    = _userservice.GetCurrentUser().Id;
                        existingList.RUT    = DateTime.Now;
                        dbcontext.SaveChanges();
                    }
                    else
                    {
                        dbcontext.UserWiseColumnNames.Add(new Teckraft.Data.Sql.UserWiseColumnName()
                        {
                            ChapterId             = data.ChapterId,
                            UserId                = _userservice.GetCurrentUser().Id,
                            chapternamedisplay    = data.chapternamedisplay,
                            chapterOwner          = data.chapterOwner,
                            ID_Category           = data.ID_Category,
                            id_comments           = data.id_comments,
                            id_data_load_date     = data.id_data_load_date,
                            id_dept               = data.id_dept,
                            ID_Issue_Detail1      = data.ID_Issue_Detail1,
                            id_location           = data.id_location,
                            ID_Logged_Date        = data.ID_Logged_Date,
                            id_pending_with_email = data.id_pending_with_email,
                            id_pending_with_name  = data.id_pending_with_name,
                            id_reported_by_email  = data.id_reported_by_email,
                            id_reported_by_name   = data.id_reported_by_name,
                            id_request            = data.id_request,
                            id_status             = data.id_status,
                            ID_Target_Date        = data.ID_Target_Date,
                            id_tat_status         = data.id_tat_status,
                            pendingSince          = data.pendingSince,
                            title = data.title,

                            RCT = DateTime.Now,
                            RCB = _userservice.GetCurrentUser().Id,
                        });
                    }
                    dbcontext.SaveChanges();
                    result.Success = true;
                    result.Message = "Comments added successfully ";
                }
            }
            catch (Exception ex)
            {
                result.Success   = false;
                result.Message   = "Unable to Save Record!";
                result.Exception = ex;
            }

            return(result);
        }
Exemple #3
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            ViewBag.multipleLogin = "******";
            if (Settings.EnableOTP)
            {
                TestOTPWebService.WebServiceSoapClient objOTP = new TestOTPWebService.WebServiceSoapClient();
                string   uname      = model.UserName;
                string   pass       = model.Password;
                string[] emailRegex = { "-", "<", ">", ";", "'" };
                for (var i = 0; i < emailRegex.Length; i++)
                {
                    if (model.UserName != null)
                    {
                        model.UserName = model.UserName.Replace(emailRegex[i], " ");
                    }

                    if (model.Password != null)
                    {
                        model.Password = model.Password.Replace(emailRegex[i], " ");
                    }
                }


                string appName = "SSOEMP";
                string appCode = "SSOEMP";

                var result = objOTP.Login(Encryptdata(uname), Encryptdata(pass), Encryptdata(appName), Encryptdata(appCode));

                if (WebSecurity.IsAccountLockedOut(model.UserName, 5, 100))
                {
                    ModelState.AddModelError("", "Account is locked due to multiple failed login attempts.");
                }
                else if (WebSecurity.IsConfirmed(model.UserName) == false)
                {
                    ModelState.AddModelError("", "Account disabled");
                }
                else if (ModelState.IsValid && result)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false);
                    var usr = WebSecurity.GetUserId(model.UserName);



                    Teckraft.Data.Sql.InitiativeHubFinalEntities DbContext = new Teckraft.Data.Sql.InitiativeHubFinalEntities();
                    var dt = DateTime.Now.AddMinutes(-22);
                    foreach (var item in DbContext.CurrentUserSessions.Where(it => it.UserId == usr && it.RCT < dt))
                    {
                        DbContext.CurrentUserSessions.Remove(item);
                    }
                    DbContext.SaveChanges();

                    var curSession = DbContext.CurrentUserSessions.FirstOrDefault(it => it.UserId == usr);
                    if (curSession != null && !model.ForcefullLogout)
                    {
                        ViewBag.multipleLogin = "******";
                        ModelState.AddModelError("", "Mutiple login not allowed");
                        WebSecurity.Logout();
                    }
                    else
                    {
                        if (curSession != null)
                        {
                            System.Web.HttpContext.Current.Application[curSession.SessionId] = null;
                            DbContext.CurrentUserSessions.Remove(curSession);
                        }
                        DbContext.CurrentUserSessions.Add(new Teckraft.Data.Sql.CurrentUserSession()
                        {
                            UserId = usr, RCT = DateTime.Now, SessionId = Session.SessionID
                        });
                        DbContext.SaveChanges();
                        Session["sessionid"] = Session.SessionID;
                        System.Web.HttpContext.Current.Application[Session.SessionID.ToString()] = Session.SessionID;
                        return(RedirectToLocal(returnUrl));
                    }
                }
                else
                {
                    if (WebSecurity.UserExists(model.UserName) && !WebSecurity.IsConfirmed(model.UserName))
                    {
                        ModelState.AddModelError("", "Your account has been blocked. Please contact SSO admin.");
                    }
                    else
                    {
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    }
                }
            }
            else
            {
                string[] emailRegex = { "-", "<", ">", ";", "'" };
                for (var i = 0; i < emailRegex.Length; i++)
                {
                    if (model.UserName != null)
                    {
                        model.UserName = model.UserName.Replace(emailRegex[i], " ");
                    }

                    if (model.Password != null)
                    {
                        model.Password = model.Password.Replace(emailRegex[i], " ");
                    }
                }


                if (WebSecurity.IsAccountLockedOut(model.UserName, 5, 100))
                {
                    ModelState.AddModelError("", "Account is locked due to multiple failed login attempts.");
                }

                else if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
                {
                    if (String.IsNullOrEmpty(returnUrl))
                    {
                        //  returnUrl = "/";
                    }

                    FormsAuthentication.SetAuthCookie(model.UserName, false);
                    var usr = WebSecurity.GetUserId(model.UserName);
                    Teckraft.Data.Sql.InitiativeHubFinalEntities DbContext = new Teckraft.Data.Sql.InitiativeHubFinalEntities();
                    var dt = DateTime.Now.AddMinutes(-22);
                    foreach (var item in DbContext.CurrentUserSessions.Where(it => it.UserId == usr && it.RCT < dt))
                    {
                        DbContext.CurrentUserSessions.Remove(item);
                    }
                    DbContext.SaveChanges();

                    var curSession = DbContext.CurrentUserSessions.FirstOrDefault(it => it.UserId == usr);
                    if (curSession != null && !model.ForcefullLogout)
                    {
                        ModelState.AddModelError("", "Mutiple login not allowed");
                        ViewBag.multipleLogin = "******";
                        WebSecurity.Logout();
                    }
                    else
                    {
                        if (curSession != null)
                        {
                            System.Web.HttpContext.Current.Application[curSession.SessionId] = null;
                            DbContext.CurrentUserSessions.Remove(curSession);
                        }
                        DbContext.CurrentUserSessions.Add(new Teckraft.Data.Sql.CurrentUserSession()
                        {
                            UserId = usr, RCT = DateTime.Now, SessionId = Session.SessionID
                        });
                        DbContext.SaveChanges();
                        Session["sessionid"] = Session.SessionID;
                        System.Web.HttpContext.Current.Application[Session.SessionID.ToString()] = Session.SessionID;

                        Session["ASP.NET_SessionId"] = Session.SessionID;
                        Response.Cookies["ASP.NET_SessionId"].Value = Session.SessionID;
                        Response.Cookies["LogOutState"].Value       = "false";

                        return(RedirectToLocal(returnUrl));
                    }
                }
                else
                {
                    if (WebSecurity.UserExists(model.UserName) && !WebSecurity.IsConfirmed(model.UserName))
                    {
                        ModelState.AddModelError("", "Your account has been blocked. Please contact SSO admin.");
                    }
                    else
                    {
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    }
                }
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #4
0
        public ActionResult Loginnew(string UserName)
        {
            //string decUserName = Decryptdata(UserName);
            LoginModel model = new LoginModel();

            //model.UserName = decUserName;
            model.UserName = UserName;
            // model.Password = Password;
            string returnUrl = null;

            ViewBag.multipleLogin = "******";
            //if (Settings.EnableOTP)
            //{
            //    string constrSSO = ConfigurationManager.ConnectionStrings["OTPConnectionString"].ConnectionString;
            //    string Password = "";
            //    using (SqlConnection con1 = new SqlConnection(constrSSO))
            //    {
            //        using (SqlCommand cmd1 = new SqlCommand())
            //        {
            //            cmd1.CommandText = "GetPassword";
            //            cmd1.CommandType = CommandType.StoredProcedure;
            //            cmd1.Parameters.AddWithValue("@UserName", UserName);
            //            cmd1.Parameters.AddWithValue("@ApplnName", "SSOEMP");
            //            cmd1.Parameters.AddWithValue("@ApplnCode", "SSOEMP");
            //            con1.Open();
            //            cmd1.Connection = con1;
            //            DataTable dt = new DataTable();
            //            SqlDataAdapter da = new SqlDataAdapter();
            //            da.SelectCommand = cmd1;
            //            da.Fill(dt);
            //            foreach (DataRow row in dt.Rows)
            //            {
            //                Password = row["password"].ToString();
            //            }
            //         }
            //    }
            //    if (Password != "")
            //    {
            //        model.Password = Password;
            //    }

            //    TestOTPWebService.WebServiceSoapClient objOTP = new TestOTPWebService.WebServiceSoapClient();
            //    string uname = model.UserName;
            //    string pass = model.Password;
            //    string[] emailRegex = { "-", "<", ">", ";", "'" };
            //    for (var i = 0; i < emailRegex.Length; i++)
            //    {
            //        if (model.UserName != null)
            //            model.UserName = model.UserName.Replace(emailRegex[i], " ");

            //        if (model.Password != null)
            //            model.Password = model.Password.Replace(emailRegex[i], " ");

            //    }


            //    string appName = "SSOEMP";
            //    string appCode = "SSOEMP";

            //    var result = objOTP.Login(Encryptdata(uname), Encryptdata(pass), Encryptdata(appName), Encryptdata(appCode));

            //    if (WebSecurity.IsAccountLockedOut(model.UserName, 5, 100))
            //    {
            //        ModelState.AddModelError("", "Account is locked due to multiple failed login attempts.");
            //    }
            //    else if (WebSecurity.IsConfirmed(model.UserName) == false)
            //    {
            //        ModelState.AddModelError("", "Account disabled");
            //    }
            //    else if (ModelState.IsValid && result)
            //    {
            //        FormsAuthentication.SetAuthCookie(model.UserName, false);
            //        var usr = WebSecurity.GetUserId(model.UserName);



            //        Teckraft.Data.Sql.InitiativeHubFinalEntities DbContext = new Teckraft.Data.Sql.InitiativeHubFinalEntities();
            //        var dt = DateTime.Now.AddMinutes(-22);
            //        foreach (var item in DbContext.CurrentUserSessions.Where(it => it.UserId == usr && it.RCT < dt))
            //        {
            //            DbContext.CurrentUserSessions.Remove(item);
            //        }
            //        DbContext.SaveChanges();

            //        var curSession = DbContext.CurrentUserSessions.FirstOrDefault(it => it.UserId == usr);
            //        if (curSession != null && !model.ForcefullLogout)
            //        {
            //            ViewBag.multipleLogin = "******";
            //            ModelState.AddModelError("", "Mutiple login not allowed");
            //            WebSecurity.Logout();
            //        }
            //        else
            //        {
            //            if (curSession != null)
            //            {
            //                System.Web.HttpContext.Current.Application[curSession.SessionId] = null;
            //                DbContext.CurrentUserSessions.Remove(curSession);
            //            }
            //            DbContext.CurrentUserSessions.Add(new Teckraft.Data.Sql.CurrentUserSession() { UserId = usr, RCT = DateTime.Now, SessionId = Session.SessionID });
            //            DbContext.SaveChanges();
            //            Session["sessionid"] = Session.SessionID;
            //            System.Web.HttpContext.Current.Application[Session.SessionID.ToString()] = Session.SessionID;
            //            return RedirectToLocal(returnUrl);
            //        }

            //    }
            //    else
            //    {
            //        if (WebSecurity.UserExists(model.UserName) && !WebSecurity.IsConfirmed(model.UserName))
            //        {
            //            ModelState.AddModelError("", "Your account has been blocked. Please contact SSO admin.");
            //        }
            //        else
            //            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            //    }

            //}
            // else
            // {
            model.Password = "******";

            string[] emailRegex = { "-", "<", ">", ";", "'" };
            for (var i = 0; i < emailRegex.Length; i++)
            {
                if (model.UserName != null)
                {
                    model.UserName = model.UserName.Replace(emailRegex[i], " ");
                }

                if (model.Password != null)
                {
                    model.Password = model.Password.Replace(emailRegex[i], " ");
                }
            }


            if (WebSecurity.IsAccountLockedOut(model.UserName, 5, 100))
            {
                ModelState.AddModelError("", "Account is locked due to multiple failed login attempts.");
            }

            else if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                if (String.IsNullOrEmpty(returnUrl))
                {
                    //  returnUrl = "/";
                }

                FormsAuthentication.SetAuthCookie(model.UserName, false);
                var usr = WebSecurity.GetUserId(model.UserName);
                Teckraft.Data.Sql.InitiativeHubFinalEntities DbContext = new Teckraft.Data.Sql.InitiativeHubFinalEntities();
                var dt = DateTime.Now.AddMinutes(-22);
                foreach (var item in DbContext.CurrentUserSessions.Where(it => it.UserId == usr && it.RCT < dt))
                {
                    DbContext.CurrentUserSessions.Remove(item);
                }
                DbContext.SaveChanges();

                var curSession = DbContext.CurrentUserSessions.FirstOrDefault(it => it.UserId == usr);
                //if (curSession != null && !model.ForcefullLogout)
                //{

                //    ModelState.AddModelError("", "Mutiple login not allowed");
                //    ViewBag.multipleLogin = "******";
                //    WebSecurity.Logout();
                //}
                //else
                //{
                if (curSession != null)
                {
                    System.Web.HttpContext.Current.Application[curSession.SessionId] = null;
                    DbContext.CurrentUserSessions.Remove(curSession);
                }
                DbContext.CurrentUserSessions.Add(new Teckraft.Data.Sql.CurrentUserSession()
                {
                    UserId = usr, RCT = DateTime.Now, SessionId = Session.SessionID
                });
                DbContext.SaveChanges();
                Session["sessionid"] = Session.SessionID;
                System.Web.HttpContext.Current.Application[Session.SessionID.ToString()] = Session.SessionID;

                Session["ASP.NET_SessionId"] = Session.SessionID;
                Response.Cookies["ASP.NET_SessionId"].Value = Session.SessionID;
                Response.Cookies["LogOutState"].Value       = "false";

                return(RedirectToLocal(returnUrl));
                //}
            }
            else
            {
                if (WebSecurity.UserExists(model.UserName) && !WebSecurity.IsConfirmed(model.UserName))
                {
                    ModelState.AddModelError("", "Your account has been blocked. Please contact SSO admin.");
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }
            //}
            // If we got this far, something failed, redisplay form
            return(View(model));
        }