コード例 #1
0
        public int AddUserLoggedInDetails(AddUserLoggedInDetailViewModel model)
        {
            try
            {
                UserLoginLogOutDetail entity = new UserLoginLogOutDetail();
                entity.LoginName   = model.LoginName;
                entity.LoginType   = model.LoginType;
                entity.LoginId     = model.LoginId;
                entity.LoginBy     = model.LoginBy;
                entity.IPDetails   = model.IPDetails;
                entity.LoginDate   = model.LoginDate;
                entity.LoginTime   = DateTime.Now;
                entity.LogoutTime  = model.LogoutTime;
                entity.LoginStatus = model.LoginStatus;
                db.UserLoginLogOutDetails.Add(entity);
                db.SaveChanges();

                return(entity.LoginDetailRowID);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #2
0
        public ActionResult VendorLogin(VendorLoginViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (string.Compare(model.CRPUserName, "", false) == 0 && string.Compare(model.CRPPassWord, "", false) == 0)
                    {
                        ModelState.AddModelError("", "Enter User Name and Password");
                    }
                    else if (string.Compare(model.CRPUserName, "", false) == 0 && string.Compare(model.CRPPassWord, "", false) != 0)
                    {
                        ModelState.AddModelError("", "Enter User Name");
                    }
                    else if (!(string.Compare(model.CRPUserName, "", false) != 0 && string.Compare(model.CRPPassWord, "", false) == 0))
                    {
                        DateTime today      = DateTime.Today;
                        string   str        = model.CRPUserName.Trim().ToLower();
                        string   str1       = model.CRPPassWord.Trim().ToLower();
                        string[] strArrays1 = str.Split(' ');
                        string[] strArrays2 = str1.Split(' ');
                        string   str2       = strArrays1[0];
                        string   str3       = strArrays2[0];

                        if (!(string.Compare(str2, "select", false) == 0 || string.Compare(str2, "exec", false) == 0 || string.Compare(str2, "execute", false) == 0 || string.Compare(str2, "drop", false) == 0 || string.Compare(str2, "truncate", false) == 0 || string.Compare(str2, "insert", false) == 0 || string.Compare(str2, "update", false) == 0 || string.Compare(str2, "delete", false) == 0 || string.Compare(str2, "union", false) == 0 || string.Compare(str2, "create", false) == 0)
                            )
                        {
                            if (!(string.Compare(str3, "select", false) == 0 || string.Compare(str3, "exec", false) == 0 || string.Compare(str3, "execute", false) == 0 || string.Compare(str3, "drop", false) == 0 || string.Compare(str3, "truncate", false) == 0 || string.Compare(str3, "insert", false) == 0 || string.Compare(str3, "update", false) == 0 || string.Compare(str3, "delete", false) == 0 || string.Compare(str2, "union", false) == 0 || string.Compare(str2, "create", false) == 0)
                                )
                            {
                                string UserName     = model.CRPUserName.Trim();
                                string UserPassword = model.CRPPassWord.Trim();
                                string encPassword  = clsCommonMethods.PasswordEncrypt(model.CRPPassWord.Trim());

                                VendorUserLoggedViewModel loggedUser = new VendorUserLoggedViewModel();
                                try
                                {
                                    loggedUser = repoAccount.GetVendorUserLoggedDetails(UserName, encPassword);
                                }
                                catch (Exception exception1)
                                {
                                    ViewBag.ErrorMsg = exception1.Message;
                                    clsCommonMethods.ErrorLog(Server.MapPath("~\\ErrorLogs\\Logfiles"), exception1.Message, exception1.StackTrace);
                                }

                                if (loggedUser == null)
                                {
                                    var activWebUsers = repoAccount.GetAllActiveVendorUsers();
                                    foreach (var webUser in activWebUsers)
                                    {
                                        if (!(webUser.CRPUserName.Trim() == UserName) || !(webUser.CRPPassWord.Trim() != encPassword))
                                        {
                                            continue;
                                        }

                                        Session["Counter"] = Convert.ToInt32(Session["Counter"]) + 1;
                                        break;
                                    }

                                    if (!(Convert.ToInt32(Session["Counter"]) >= 3))
                                    {
                                        ViewBag.ErrorMsg = "Login Failed.Try Again!";
                                        clsCommonMethods.UserLog(Server.MapPath("~\\ErrorLogs\\Unauthorized_UserLog"), UserName, UserPassword, "Vendor");
                                        return(View());
                                    }
                                    else
                                    {
                                        Session["Counter"] = 0;
                                        UpdateVendorUserBlockStatusViewModel userBlocked = new UpdateVendorUserBlockStatusViewModel();
                                        userBlocked.UserID      = UserName;
                                        userBlocked.BlockedDate = DateTime.Now;
                                        userBlocked.Status      = 3;

                                        repoAccount.BlockedVendorUser(userBlocked);
                                        repoAccount.SaveChanges();

                                        ViewBag.ErrorMsg = "User has been Blocked, Please contact to Administrator!";
                                        Session.Abandon();
                                        return(View());
                                    }
                                }
                                else
                                {
                                    Session["UserName"]         = UserName;
                                    Session["VendorLoginRowID"] = loggedUser.VendorLoginRowID;
                                    Session["VendorRowID"]      = loggedUser.VendorRowID;
                                    Session["VendorName"]       = loggedUser.VendorName;
                                    Session["VendorEmaiID"]     = loggedUser.VendorEmaiID;
                                    Session["ContactPerson"]    = loggedUser.ContactPerson;
                                    Session["MobileNo"]         = loggedUser.MobileNo;
                                    Session["UserType"]         = loggedUser.UserType;
                                    Session["CreatedBy"]        = loggedUser.CreatedBy;
                                    Session["Valid"]            = 1;

                                    if (Convert.ToInt32(Session["Valid"]) == 1)
                                    {
                                        DateTime dateTime          = DateTime.Today;
                                        TimeSpan TimeSinceCreation = new TimeSpan();

                                        if (loggedUser.ModifiedTime != null)
                                        {
                                            TimeSinceCreation = dateTime.Subtract(loggedUser.ModifiedTime.Value);
                                        }
                                        else
                                        {
                                            TimeSinceCreation = dateTime.Subtract(loggedUser.CreatedTime.Value);
                                        }

                                        if (TimeSinceCreation.Days > 179)
                                        {
                                            ViewBag.ErrorMsg = "Your password has expired. Please contact your Administrator!";
                                            Session.Abandon();
                                            return(View());
                                        }
                                        else if (TimeSinceCreation.Days < 0)
                                        {
                                            clsCommonMethods.UserLog(Server.MapPath("~\\ErrorLogs\\Unauthorized_UserLog"), UserName, UserPassword, "Vendor");
                                            ViewBag.ErrorMsg = "Invalid login. Please Try again!";
                                            Session.Abandon();
                                            return(View());
                                        }
                                    }

                                    AddUserLoggedInDetailViewModel loggedInDetails = new AddUserLoggedInDetailViewModel();
                                    loggedInDetails.LoginName = loggedUser.VendorName;
                                    if (loggedUser.UserType == 0)
                                    {
                                        loggedInDetails.LoginType = "Vendor";
                                    }
                                    else
                                    {
                                        loggedInDetails.LoginType = "Vendor's User";
                                    }

                                    loggedInDetails.LoginId     = UserName;
                                    loggedInDetails.LoginBy     = "Vendor";
                                    loggedInDetails.IPDetails   = Request.UserHostAddress;
                                    loggedInDetails.LoginDate   = DateTime.Now;
                                    loggedInDetails.LoginStatus = 1;

                                    Session["LoginDetailRowID"] = repoAccount.AddUserLoggedInDetails(loggedInDetails);
                                }

                                FormsAuthentication.SetAuthCookie(UserName, false);
                                return(RedirectToAction("Index", "Home", new { area = "Partner" }));
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Enter Password");
                    }
                }
                else
                {
                    var query = from state in ModelState.Values
                                from error in state.Errors
                                select error.ErrorMessage;

                    var    errorList = query.ToList();
                    string strError  = string.Empty;
                    foreach (string str in errorList)
                    {
                        strError += str + "\n";
                    }

                    ModelState.AddModelError("", strError);
                }
            }
            catch (Exception Ex)
            {
                ViewBag.ErrorMsg = Ex.Message;
                clsCommonMethods.ErrorLog(Server.MapPath("~\\ErrorLogs\\Logfiles"), Ex.Message, Ex.StackTrace);
            }

            return(View());
        }
コード例 #3
0
        public ActionResult CandidateLogin(CandidateLoginViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (string.Compare(model.CRPUserName, "", false) == 0 && string.Compare(model.CRPPassWord, "", false) == 0)
                    {
                        ModelState.AddModelError("", "Enter User Name and Password");
                    }
                    else if (string.Compare(model.CRPUserName, "", false) == 0 && string.Compare(model.CRPPassWord, "", false) != 0)
                    {
                        ModelState.AddModelError("", "Enter User Name");
                    }
                    else if (!(string.Compare(model.CRPUserName, "", false) != 0 && string.Compare(model.CRPPassWord, "", false) == 0))
                    {
                        DateTime today      = DateTime.Today;
                        string   str        = model.CRPUserName.Trim().ToLower();
                        string   str1       = model.CRPPassWord.Trim().ToLower();
                        string[] strArrays1 = str.Split(' ');
                        string[] strArrays2 = str1.Split(' ');
                        string   str2       = strArrays1[0];
                        string   str3       = strArrays2[0];

                        if (!(string.Compare(str2, "select", false) == 0 || string.Compare(str2, "exec", false) == 0 || string.Compare(str2, "execute", false) == 0 || string.Compare(str2, "drop", false) == 0 || string.Compare(str2, "truncate", false) == 0 || string.Compare(str2, "insert", false) == 0 || string.Compare(str2, "update", false) == 0 || string.Compare(str2, "delete", false) == 0 || string.Compare(str2, "union", false) == 0 || string.Compare(str2, "create", false) == 0)
                            )
                        {
                            if (!(string.Compare(str3, "select", false) == 0 || string.Compare(str3, "exec", false) == 0 || string.Compare(str3, "execute", false) == 0 || string.Compare(str3, "drop", false) == 0 || string.Compare(str3, "truncate", false) == 0 || string.Compare(str3, "insert", false) == 0 || string.Compare(str3, "update", false) == 0 || string.Compare(str3, "delete", false) == 0 || string.Compare(str2, "union", false) == 0 || string.Compare(str2, "create", false) == 0)
                                )
                            {
                                string UserName     = model.CRPUserName.Trim();
                                string UserPassword = model.CRPPassWord.Trim();
                                string encPassword  = clsCommonMethods.PasswordEncrypt(model.CRPPassWord.Trim());

                                CandidateUserLoggedViewModel loggedUser = new CandidateUserLoggedViewModel();
                                try
                                {
                                    if (IsValidEmail(UserName))
                                    {
                                        loggedUser = repoAccount.GetInsuffCandidateUserLoggedDetails(UserName, encPassword);
                                    }
                                    else
                                    {
                                        loggedUser = repoAccount.GetCandidateUserLoggedDetails(UserName, encPassword);
                                    }
                                }
                                catch (Exception exception1)
                                {
                                    ViewBag.ErrorMsg = exception1.Message;
                                    clsCommonMethods.ErrorLog(Server.MapPath("~\\ErrorLogs\\Logfiles"), exception1.Message, exception1.StackTrace);
                                }

                                if (loggedUser == null)
                                {
                                    this.Session.Abandon();
                                    ViewBag.ErrorMsg = "Login Failed.Try Again!";
                                    clsCommonMethods.UserLog(Server.MapPath("~\\ErrorLogs\\Unauthorized_UserLog"), UserName, UserPassword, "Candidate");
                                    return(View());
                                }
                                else
                                {
                                    Session["CadidateUserName"]   = UserName;
                                    Session["CandidateUserRowID"] = loggedUser.CandidateUserRowID;
                                    Session["ClientRowID"]        = loggedUser.ClientRowID;
                                    Session["HRApproval"]         = loggedUser.HRApprovalRequired;
                                    Session["TempPersonalRowID"]  = loggedUser.TempPersonalRowID;
                                    Session["LoginCandidateName"] = loggedUser.CandidateName;
                                    Session["CandidateEmail"]     = loggedUser.CandidateEmail;
                                    Session["YTRApplicable"]      = loggedUser.YTRApplicable;
                                    Session["CreatedBy"]          = loggedUser.CreatedBy;
                                    Session["ClientUType"]        = "Candidate";
                                    Session["Valid"] = 1;

                                    if (Convert.ToInt32(Session["Valid"]) == 1)
                                    {
                                        DateTime dateTime          = DateTime.Today;
                                        TimeSpan TimeSinceCreation = new TimeSpan();

                                        if (loggedUser.ModifiedTime != null)
                                        {
                                            TimeSinceCreation = dateTime.Subtract(loggedUser.ModifiedTime.Value);
                                        }
                                        else
                                        {
                                            TimeSinceCreation = dateTime.Subtract(loggedUser.CreatedTime.Value);
                                        }

                                        if (TimeSinceCreation.Days > 15)
                                        {
                                            ViewBag.ErrorMsg = "Your password has expired. Please contact your Administrator!";
                                            try
                                            {
                                                UpdateCandidateLoginExpireStatusViewModel loginExpire = new UpdateCandidateLoginExpireStatusViewModel();
                                                loginExpire.UserID   = UserName;
                                                loginExpire.UserType = 0;
                                                loginExpire.Status   = 0;

                                                repoAccount.ExpireCandidateLogin(loginExpire);
                                                repoAccount.SaveChanges();
                                            }
                                            catch (Exception exception11)
                                            {
                                                clsCommonMethods.ErrorLog(Server.MapPath("~\\ErrorLogs\\Logfiles"), exception11.Message, exception11.StackTrace);
                                            }

                                            Session.Abandon();
                                            return(View());
                                        }
                                        else if (TimeSinceCreation.Days < 0)
                                        {
                                            clsCommonMethods.UserLog(Server.MapPath("~\\ErrorLogs\\Unauthorized_UserLog"), UserName, UserPassword, "Candidate");
                                            ViewBag.ErrorMsg = "Invalid login. Please Try again!";
                                            Session.Abandon();
                                            return(View());
                                        }
                                    }

                                    AddUserLoggedInDetailViewModel loggedInDetails = new AddUserLoggedInDetailViewModel();
                                    loggedInDetails.LoginName   = loggedUser.CandidateName;
                                    loggedInDetails.LoginType   = loggedUser.CreatedBy;
                                    loggedInDetails.LoginId     = UserName;
                                    loggedInDetails.LoginBy     = "Candidate";
                                    loggedInDetails.IPDetails   = Request.UserHostAddress;
                                    loggedInDetails.LoginDate   = DateTime.Now;
                                    loggedInDetails.LoginStatus = 1;

                                    Session["LoginDetailRowID"] = repoAccount.AddUserLoggedInDetails(loggedInDetails);
                                }

                                FormsAuthentication.SetAuthCookie(UserName, false);
                                if (IsValidEmail(UserName))
                                {
                                    Session["CInsufficiency"] = "YES";
                                    return(RedirectToAction("Index", "CandidateInsuff", new { area = "Candidate" }));
                                }
                                else
                                {
                                    return(RedirectToAction("Index", "Home", new { area = "Candidate" }));
                                }
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Enter Password");
                    }
                }
                else
                {
                    var query = from state in ModelState.Values
                                from error in state.Errors
                                select error.ErrorMessage;

                    var    errorList = query.ToList();
                    string strError  = string.Empty;
                    foreach (string str in errorList)
                    {
                        strError += str + "\n";
                    }

                    ModelState.AddModelError("", strError);
                }
            }
            catch (Exception Ex)
            {
                ViewBag.ErrorMsg = Ex.Message;
                clsCommonMethods.ErrorLog(Server.MapPath("~\\ErrorLogs\\Logfiles"), Ex.Message, Ex.StackTrace);
            }

            return(View());
        }