コード例 #1
0
        public JsonResult getColumnDetails(int UserId, string SystemChapterName)
        {
            var result = new Teckraft.Data.ListQueryResult <UserWiseColumnName>();
            var list   = new List <UserWiseColumnName>();

            using (Teckraft.Data.Sql.InitiativeHubFinalEntities dbcontext = new Teckraft.Data.Sql.InitiativeHubFinalEntities())
            {
                var chap = dbcontext.ChapterMasters.FirstOrDefault(it => it.ChapterNameFromSystem == SystemChapterName);
                if (chap != null)
                {
                    var lq = dbcontext.UserWiseColumnNames.FirstOrDefault(it => it.ChapterId == chap.Id && it.UserId == UserId);
                    if (lq != null)
                    {
                        // lq.ChapterId = chap.Id;
                        list.Add(mapper.Map(lq));
                    }
                }
                // var lq = dbcontext.(SystemChapterName, RoleName, Email);
                //foreach (var t in lq)
                //{
                //    list.Add(new HodNames
                //    {
                //        SAPDivisionName = t.SAPDivisionName,
                //        SAPDivisionCode = t.SAPDivisionCode,
                //        HodEmail = t.HodEmail,
                //    });
                //}
            }
            result.Items = list;
            // return Json(result, JsonRequestBehavior.AllowGet);
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public DbActionResult <IssueManagementAnchorComment> Post(IssueManagementAnchorComment items)
        {
            var    result  = new DbActionResult <IssueManagementAnchorComment>();
            bool   EFlag   = false;
            string EmailTo = "";

            try
            {
                var data = items;

                string[] emailRegex = { "-", "<", ">", ";", "'" };
                for (var i = 0; i < emailRegex.Length; i++)
                {
                    if (data.ID_Comments != null)
                    {
                        data.ID_Comments = data.ID_Comments.Replace(emailRegex[i], " ");
                    }
                }
                using (var dbcontext = new Teckraft.Data.Sql.InitiativeHubFinalEntities())
                {
                    var chap = dbcontext.ChapterMasters.FirstOrDefault(it => it.ChapterNameFromSystem == data.id_System_Name && it.EmailFlag == true);
                    if (chap != null)
                    {
                        data.id_System_Name = chap.ChapterNameFromSystem;
                        EFlag   = chap.EmailFlag.Value;
                        EmailTo = chap.EmailTo;
                    }
                }

                data.RCB = _userservice.GetCurrentUser();
                data     = IssueService.Add(data);

                // if (EFlag == true)
                //  {
                // if (data.EmailFlag == true && EmailTo != null)
                //{
                //var tmplt1 = templateService.GetTemplateforComments(data);
                // emailService.SendEmail(tmplt1, "*****@*****.**", EmailTo, "", "");
                // emailService.SendEmail(tmplt1, "*****@*****.**", EmailTo, "*****@*****.**", "");
                // }
                //}

                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);
        }
コード例 #3
0
ファイル: DataHelper.cs プロジェクト: pidiliteit/CWPPhase1
 public static Core.Domian.Settings.User GetBasisUser()
 {
     using (
         var dbcontext = new Teckraft.Data.Sql.InitiativeHubFinalEntities())
     {
         var rec = dbcontext.UserDetails.FirstOrDefault(it => it.UserId == 10723);
         return(new Core.Domian.Settings.User()
         {
             Id = rec.UserId, Title = rec.Title, Email = rec.Email, UserName = rec.UserName
         });
     }
 }
コード例 #4
0
        public ListQueryResult <webpages_Roles> Get(string q)
        {
            ListQuery <webpages_Roles> query = new ListQuery <webpages_Roles>();

            if (!string.IsNullOrEmpty(q))
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                query = js.Deserialize <ListQuery <webpages_Roles> >(q);
            }

            var list = new List <webpages_Roles>();

            using (Teckraft.Data.Sql.InitiativeHubFinalEntities dbcontext = new Teckraft.Data.Sql.InitiativeHubFinalEntities())
            {
                if (query.Parameters != null)
                {
                    if (query.Parameters.Count > 0)
                    {
                        foreach (var item in query.Parameters)
                        {
                            if (item.Name == "ExistingRole")
                            {
                                var role    = item.Value;
                                var dbquery = dbcontext.webpages_Roles.Where(it => it.RoleId > 0 && it.RoleName != role);
                                foreach (var dbitem in dbquery.ToList())
                                {
                                    list.Add(mapper.Map(dbitem));
                                }
                            }
                            else
                            {
                                var dbquery = dbcontext.webpages_Roles.Where(it => it.RoleId > 0);
                                foreach (var dbitem in dbquery.ToList())
                                {
                                    list.Add(mapper.Map(dbitem));
                                }
                            }
                        }
                    }
                }
            }

            return(new ListQueryResult <webpages_Roles>()
            {
                Items = list
            });
        }
コード例 #5
0
        public ListQueryResult <StatusMaster> Get(string q)
        {
            var result = new ListQueryResult <Teckraft.Core.Domian.Settings.StatusMaster>();

            using (Teckraft.Data.Sql.InitiativeHubFinalEntities dbcontext = new Teckraft.Data.Sql.InitiativeHubFinalEntities())
            {
                var dbquery = dbcontext.StatusMasters.Where(it => it.Id > 0);
                foreach (var item in dbquery.OrderByDescending(it => it.StatusDesc))
                {
                    if (result.Items == null)
                    {
                        result.Items = new List <Teckraft.Core.Domian.Settings.StatusMaster>();
                    }
                    result.Items.Add(_StatusMapper.Map(item));
                }
            }

            return(result);
        }
コード例 #6
0
        public JsonResult getHodwiseCount(string SystemChapName, string RoleName, string Email)
        {
            var result = new Teckraft.Data.ListQueryResult <HODWiseCount>();
            var list   = new List <HODWiseCount>();

            using (Teckraft.Data.Sql.InitiativeHubFinalEntities dbcontext = new Teckraft.Data.Sql.InitiativeHubFinalEntities())
            {
                var lq = dbcontext.spHodCount(SystemChapName, RoleName, Email).AsQueryable();
                foreach (var t in lq)
                {
                    list.Add(new HODWiseCount
                    {
                        SAPDivisionName = t.SAPDivisionName,
                        count           = t.count,
                    });
                }
            }
            result.Items = list;
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #7
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"));
        }
コード例 #8
0
        public ListQueryResult<Core.Domian.Settings.IssueManagementCommentLog> GetByQuery(ListQuery<Core.Domian.Settings.IssueManagementCommentLog> query)
        {
            var result = new ListQueryResult<Teckraft.Core.Domian.Settings.IssueManagementCommentLog>();
            var list = new List<Teckraft.Core.Domian.Settings.IssueManagementCommentLog>();

            using (Teckraft.Data.Sql.InitiativeHubFinalEntities dbcontext = new Teckraft.Data.Sql.InitiativeHubFinalEntities())
            {
                var linqquery = dbcontext.IssueManagementCommentLogs.Where(it => it.Id > 0);
                if (query.Parameters.Count > 0)
                {
                    foreach (var item in query.Parameters)
                    {
                        if (item.Name == "RequestNo")
                        {
                            var val = item.Value;
                            linqquery = linqquery.Where(k => k.ID_Request == val);
                        }
                        else if (item.Name == "ChapterName")
                        {
                            var val = item.Value;
                            linqquery = linqquery.Where(j => j.id_System_Name == val);
                        }
                        else if (item.Name == "PendingWithEmail")
                        {
                            var val = (item.Value);
                            linqquery = linqquery.Where(it => (it.ID_Pending_With_Email == val));
                        }
                    }
                    linqquery = linqquery.OrderByDescending(it => it.RCT); 
                    foreach (var dbitem in linqquery)
                    {
                        list.Add(mappingProvider.Map(dbitem));
                    }

                }
            }

            result.Items = list;
            return result;
        }
コード例 #9
0
        public JsonResult getHodName(string SystemChapterName, string RoleName, string Email)
        {
            var result = new Teckraft.Data.ListQueryResult <HodNames>();
            var list   = new List <HodNames>();

            using (Teckraft.Data.Sql.InitiativeHubFinalEntities dbcontext = new Teckraft.Data.Sql.InitiativeHubFinalEntities())
            {
                //var lq = dbcontext.spHodName(SystemChapterName);
                var lq = dbcontext.spHodName(SystemChapterName, RoleName, Email);
                foreach (var t in lq)
                {
                    list.Add(new HodNames
                    {
                        SAPDivisionName = t.SAPDivisionName,
                        SAPDivisionCode = t.SAPDivisionCode,
                        HodEmail        = t.HodEmail,
                    });
                }
            }
            result.Items = list;
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #10
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);
        }
コード例 #11
0
        public DbActionResult <IssueManagementCommentLog> Post(IssueManagementCommentLog items)
        {
            var    result     = new DbActionResult <IssueManagementCommentLog>();
            bool   EFlag      = false;
            string EmailTo    = "";
            string AncEmail   = "";
            string EmailCC    = "";
            string AnchorName = "";

            try
            {
                var data = items;

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

                var csc = new CSC();
                using (var dbcontext = new Teckraft.Data.Sql.InitiativeHubFinalEntities())
                {
                    //var chap = dbcontext.ChapterMasters.FirstOrDefault(it => it.ChapterNameFromSystem == data.id_System_Name && it.EmailFlag == true);
                    //if (chap != null)
                    //{
                    //    data.id_System_Name = chap.ChapterNameFromSystem;
                    //    EFlag = chap.EmailFlag.Value;
                    //    EmailTo = chap.EmailTo;
                    //}

                    var chap1 = dbcontext.ChapterMasters.FirstOrDefault(it => it.ChapterNameFromSystem == data.id_System_Name);
                    if (chap1 != null)
                    {
                        if (chap1.ChapterNameFromSystem == "Dealer Feedback" || chap1.ChapterNameFromSystem == "WSS Service Cell" || chap1.ChapterNameFromSystem == "MyPidilite" || chap1.ChapterNameFromSystem == "Customer Service Cell")
                        {
                            var em = dbcontext.ChapterMasters.FirstOrDefault(o => o.ChapterNameFromSystem == data.id_System_Name);
                            EmailCC  = em.EmailCC;
                            AncEmail = em.EmailTo;
                        }
                        else
                        {
                            string AncData = dbcontext.ChapterOwnerMappings.FirstOrDefault(it => it.ChapterId == chap1.Id).ChapterOwner.ToString();
                            AncEmail = dbcontext.UserDetails.FirstOrDefault(p => p.UserName == AncData).Email.ToString();
                        }
                        //for getting Anchor Name
                        var q = (from pd in dbcontext.ChapterOwnerMappings
                                 join od in dbcontext.UserDetails on pd.ChapterOwner equals od.UserName
                                 where pd.ChapterId == chap1.Id
                                 select new
                        {
                            od.Title,
                        }).FirstOrDefault();
                        if (q != null)
                        {
                            AnchorName = q.Title;
                        }
                    }


                    if (items.id_System_Name == "Customer Service Cell")
                    {
                        var cs = dbcontext.GetCSCDataBYRequestNo(items.ID_Request).FirstOrDefault();
                        csc.ContactEmail = cs.ContactEmail;
                        csc.ContactNo    = cs.contactNo;
                    }
                }

                data.RCB = _userservice.GetCurrentUser();
                data     = IssueService.Add(data);
                //if (EFlag == true) {
                //    if (data.EmailFlag == true && EmailTo != null) {
                //        var tmplt1 = templateService.GetTemplateforComments(data);
                //       // emailService.SendEmail(tmplt1, "*****@*****.**", EmailTo, "", "");
                //        emailService.SendEmail(tmplt1, "*****@*****.**", EmailTo, "*****@*****.**", "");
                //    }
                //}



                var tmplt1 = templateService.GetTemplateforAnchor(data, AnchorName, csc);
                //emailService.SendEmail(tmplt1, "[email protected] ", "*****@*****.**","", "");
                if (tmplt1.Subject != "")
                {
                    //emailService.SendEmail(tmplt1, "[email protected] ", "*****@*****.**", "", "");
                    emailService.SendEmail(tmplt1, "[email protected] ", AncEmail, EmailCC, "");
                }

                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);
        }
コード例 #12
0
        public JsonResult getChapterDetails(string ResponsibleEmail, string Owner)
        {
            var    result      = new Teckraft.Data.ListQueryResult <ChapterMaster>();
            var    list        = new List <ChapterMaster>();
            string constrSSO   = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            string newUserName = "";


            using (SqlConnection con1 = new SqlConnection(constrSSO))
            {
                using (SqlCommand cmd1 = new SqlCommand())
                {
                    // SqlCommand cmd1 = new SqlCommand("spGetChaptersforResponsiblePerson", con1);
                    cmd1.CommandText = "spGetChaptersforResponsiblePerson";
                    cmd1.CommandType = CommandType.StoredProcedure;
                    cmd1.Parameters.AddWithValue("@ResponsibleEmail", ResponsibleEmail);
                    cmd1.Parameters.AddWithValue("@Owner", Owner);
                    con1.Open();
                    cmd1.Connection = con1;
                    DataTable      dt = new DataTable();
                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = cmd1;
                    da.Fill(dt);
                    string TempChapterName = "";
                    int    countChapter    = 0;
                    if (dt.Rows.Count > 0)
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            TempChapterName = row["ChapterNameFromSystem"].ToString();
                            using (var dbcontext = new Teckraft.Data.Sql.InitiativeHubFinalEntities())
                            {
                                if (TempChapterName == "MyPidilite" || TempChapterName == "WSS Service Cell")
                                {
                                    var getChapterName = dbcontext.spGetChaptersNameforResponsiblePerson(ResponsibleEmail, Owner, TempChapterName).ToList();
                                    countChapter = getChapterName.Count();
                                }
                            }

                            // DateTime dt1 = DateTime.ParseExact((row["id_data_load_date"].ToString()), "yyyy-MM-dd", null);
                            if ((TempChapterName != "MyPidilite" && TempChapterName != "WSS Service Cell") || countChapter > 0)
                            {
                                list.Add(new ChapterMaster
                                {
                                    ChapterNameDisplay    = row["chapternamedisplay"].ToString(),
                                    ChapterOwner          = row["ChapterOwner"].ToString(),
                                    RunDate               = row["id_data_load_date"].ToString(),
                                    ChapterNameFromSystem = row["ChapterNameFromSystem"].ToString(),
                                    EditFlag              = bool.Parse(row["editflag"].ToString()),
                                    IssueCount            = int.Parse(row["issueCount"].ToString()),
                                });
                            }
                        }
                    }
                    else
                    {
                        using (var dbcontext = new Teckraft.Data.Sql.InitiativeHubFinalEntities())
                        {
                            var getChapterName = dbcontext.spGetChaptersNameforResponsiblePerson(ResponsibleEmail, Owner, TempChapterName).ToList();
                            foreach (var i in getChapterName)
                            {
                                list.Add(new ChapterMaster
                                {
                                    ChapterNameDisplay    = i.chapternamedisplay.ToString(),
                                    ChapterOwner          = i.ChapterOwner.ToString(),
                                    RunDate               = i.id_data_load_date.ToString(),
                                    ChapterNameFromSystem = i.chapternamefromsystem.ToString(),
                                    EditFlag              = bool.Parse(i.editflag.ToString()),
                                    IssueCount            = int.Parse(i.issueCount.ToString()),
                                });
                            }
                        }
                    }
                    con1.Close();
                }
            }

            result.Items = list;
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #13
0
        public JsonResult GenerateOTP(string UserName)
        {
            //if(
            string[] emailRegex = { "-", "<", ">", ";", "'" };
            for (var i = 0; i < emailRegex.Length; i++)
            {
                if (UserName != null)
                {
                    UserName = UserName.Replace(emailRegex[i], " ");
                }
            }

            Teckraft.Web.Models.DbActionResult <string>  result    = new Teckraft.Web.Models.DbActionResult <string>();
            Teckraft.Data.Sql.InitiativeHubFinalEntities DbContext = new Teckraft.Data.Sql.InitiativeHubFinalEntities();
            var UserExist = DbContext.UserProfiles.FirstOrDefault(it => it.UserName.ToLower() == UserName.ToLower());

            if (UserExist != null && WebSecurity.IsConfirmed(UserName))
            {
                var User = DbContext.UserDetails.FirstOrDefault(it => it.UserName.ToLower() == UserName.ToLower());
                if (string.IsNullOrEmpty(User.MobileNo) && string.IsNullOrEmpty(User.Email))
                {
                    result.Message = "User's Email address and Mobile number are not updated";
                    result.Success = false;
                }
                else
                {
                    TestOTPWebService.WebServiceSoapClient pilcrsOTP = new TestOTPWebService.WebServiceSoapClient();
                    var res = false;
                    if (string.IsNullOrEmpty(User.MobileNo))
                    {
                        User.MobileNo = "2222222222";
                    }
                    if (!(string.IsNullOrEmpty(User.MobileNo)))
                    {
                        try
                        {
                            res            = pilcrsOTP.Password(Encryptdata(UserName), Encryptdata(User.MobileNo), Encryptdata("SSOEMP"), Encryptdata("SSOEMP"), Encryptdata("0"));
                            result.Message = "An OTP message has been sent to your number or email";
                            result.Success = true;
                        }
                        catch (Exception ex) {
                            result.Message = "Error sending OTP please try later";
                        }
                    }
                    if (!(string.IsNullOrEmpty(User.Email)))
                    {
                        try
                        {
                            //Models.OTP.OTPEntities dbcontext = new Models.OTP.OTPEntities();
                            //var otp = dbcontext.OTPs.OrderByDescending(it => it.Time).FirstOrDefault(it => it.UserName == User.UserName && it.ApplnCode == "ASF");
                            //if (otp != null)
                            //{
                            //    System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
                            //    client.Send("*****@*****.**", User.Email, "OTP for Pidilite ASF System", "Dear user\n Your OTP for Pidilite ASF System is " + otp.Password + "\nRegards\nASF System Team");
                            //    result.Message = "An OTP message has been sent to your number or email";
                            //}
                        }
                        catch (Exception ex) {
                            result.Message = "Error sending OTP please try later";
                        }
                    }
                }
            }
            else
            {
                result.Message = "Invalid Username";
                result.Success = false;
            }
            return(Json(result));
        }
コード例 #14
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));
        }
コード例 #15
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));
        }