Пример #1
0
        public ActionResult Logout()
        {
            if (SessionContext != null && SessionContext.User != null)
            {
                using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction())
                {
                    try
                    {
                        SessionContext.UserSession.SessionPeriod.To = DateTime.Now;
                        SessionContext.UserSession.LogoutMessage    = MessageException.AuthenMessage.Logout;
                        SessionContext.UserSession.Save(SessionContext);

                        SessionContext.Log(0, PageID, 0, MessageException.AuthenMessage.Logout, MessageException.Success(SessionContext.User.ID.ToString()));

                        tx.Commit();
                    }
                    catch (Exception ex)
                    {
                        WebLogger.Error(ex.Message);
                        SessionContext.Log(0, PageID, 0, MessageException.AuthenMessage.Logout, MessageException.Fail(ex.Message));
                        tx.Rollback();
                    }
                }
            }

            Session.Clear();
            Session.Abandon();

            return(RedirectToAction("Index", "Login"));
        }
Пример #2
0
        public ActionResult LogOut()
        {
            if (SessionContext != null)
            {
                using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction())
                {
                    try
                    {
                        SessionContext.UserSession.SessionPeriod.To = DateTime.Now;
                        SessionContext.UserSession.LogoutMessage    = "Logout";
                        SessionContext.UserSession.Save(SessionContext);

                        tx.Commit();
                    }
                    catch (Exception ex)
                    {
                        WebLogger.Error(ex.GetAllMessages());
                        tx.Rollback();
                    }
                }
            }

            Session.Clear();
            Session.Abandon();

            return(RedirectToAction("Index", "Login"));
        }
Пример #3
0
        public ActionResult LogOut()
        {
            try
            {
                SessionContext.LogOut(pageID);
            }
            catch (Exception ex)
            {
                WebLogger.Error(ex.GetAllMessages());
            }

            Session.Clear();
            Session.Abandon();

            return(RedirectToAction("Index", "Login"));
        }
Пример #4
0
        public static async Task <AuthToken> GetAuthTokenAsync(string oAuthServerEndPoint, string apiKey, string clientSecret)
        {
            var authToken = new AuthToken();

            //Connect to Facebook servers
            using (var client = new HttpClient())
            {
                var authData = new[]
                {
                    new KeyValuePair <string, string>("grant_type", "client_credentials"),
                    new KeyValuePair <string, string>("client_id", apiKey),
                    new KeyValuePair <string, string>("client_secret", clientSecret)
                };

                //Retrieve authentication token from Twitter oauth2 server
                using (var content = new FormUrlEncodedContent(authData))
                {
                    content.Headers.Clear();
                    content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

                    try
                    {
                        authToken = await client.PostAsync(oAuthServerEndPoint, content)
                                    .Result.Content.ReadAsAsync <AuthToken>();
                    }
                    catch (HttpRequestException ex)
                    {
                        WebLogger.Error(ex.Message);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Error in GetAuthTokenAsync", ex);
                    }
                }
            }

            return(authToken);
        }
Пример #5
0
        public string Authentication(string idCard, string nameEng, string status)
        {
            try
            {
                WebLogger.Warn("Authenticating");

                Dictionary <string, object>   jsonResult = new Dictionary <string, object>();
                IList <SelfAuthenticatedUser> users      = SessionContext.PersistenceSession.QueryOver <SelfAuthenticatedUser>().List();
                IList <SelfAuthenticatedUser> user       = users.Where(s => s.LoginName.ToLowerInvariant() == nameEng.ToLowerInvariant() &&
                                                                       s.Person.OfficialIDNo == idCard &&
                                                                       s.UserRoles[0].Role.Id == int.Parse(status) &&
                                                                       !s.IsDisable &&
                                                                       s.IsEffective).ToList();



                if (0 < user.Count)
                {
                    if (user.Count != 1)
                    {
                        throw new Exception("User have more than one. System error.");
                    }

                    if (!user[0].IsBuiltin)
                    {
                        IList <iSabaya.UserSession> userSessions = SessionContext.PersistenceSession
                                                                   .QueryOver <iSabaya.UserSession>()
                                                                   .Where(us => us.User.ID == user[0].ID &&
                                                                          us.SessionPeriod.To == iSabaya.TimeInterval.MaxDate)
                                                                   .List();

                        if (userSessions.Any(u => u.User.ID == user[0].ID))
                        {
                            jsonResult.Add("result", 0);
                            jsonResult.Add("target", "");
                            jsonResult.Add("message", "Login Failed.");
                            SessionContext.StartFailedSession(null, idCard, Session.SessionID, "Login Attemp.");

                            return(new JavaScriptSerializer().Serialize(jsonResult));
                        }
                    }

                    BudgetConfiguration.CurrentConfiguration = GetConfiguration(SessionContext, SessionContext.MySystem.SystemID);
                    SessionContext.StartNewSession(user[0], Session.SessionID);

                    string targetPath = "";
                    switch (user[0].UserRoles[0].Role.Id)
                    {
                    case 1:
                        targetPath = FullUrl("Government");
                        break;

                    case 2:
                        targetPath = FullUrl("Budgetor");
                        break;

                    case 3:
                        targetPath = FullUrl("Evaluation");
                        break;

                    case 4:
                        targetPath = FullUrl("Admin");
                        break;

                    default:
                        throw new Exception("User Role Invalid.");
                    }


                    jsonResult.Add("result", 1);
                    jsonResult.Add("target", targetPath);
                    jsonResult.Add("message", "");
                }
                else
                {
                    jsonResult.Add("result", 0);
                    jsonResult.Add("target", "");
                    jsonResult.Add("message", "Login Failed.");
                    SessionContext.StartFailedSession(null, idCard, Session.SessionID, "Login Failed.");
                }

                WebLogger.Warn("End Authenticating");
                return(new JavaScriptSerializer().Serialize(jsonResult));
            }
            catch (Exception ex)
            {
                WebLogger.Error(ex.GetAllMessages());

                Dictionary <string, object> jsonResult = new Dictionary <string, object>();
                jsonResult.Add("result", 0);
                jsonResult.Add("target", "");
                jsonResult.Add("message", ex.ToString());

                SessionContext.StartFailedSession(null, idCard, Session.SessionID, ex.Message);

                SessionContext.Log(0, this.pageID, 0, "Login", "Fail : " + ex.Message);

                return(new JavaScriptSerializer().Serialize(jsonResult));
            }
        }
Пример #6
0
        public string Authentication(string idCard, string nameEng, string status)
        {
            try
            {
                WebLogger.Warn("Authenticating");

                Dictionary <string, object> jsonResult = new Dictionary <string, object>();

                User user = null;

                switch (AuthenticateManager.Authenticate(SessionContext, SystemEnum.RiskAssessmentAnalysisSystem, idCard, nameEng, ref user))
                {
                case AuthenticateManager.AuthenState.AuthenticationSuccess:

                    BudgetConfiguration.CurrentConfiguration = GetConfiguration(SessionContext, SessionContext.MySystem.SystemID);
                    SessionContext.StartNewSession(user, Session.SessionID);

                    string targetPath = "";
                    switch (user.UserRoles[0].Role.Id)
                    {
                    case 1:
                        targetPath = FullUrl("Government");        //ส่วนราชการ
                        break;

                    case 2:
                        targetPath = FullUrl("Budgetor");        //ทำงบประมาณ
                        break;

                    case 3:
                        targetPath = FullUrl("Evaluation");        //เจ้าหน้าที่ประเมินงบ
                        break;

                    case 4:
                        targetPath = FullUrl("Admin");        //ผู้ดูแลระบบ
                        break;

                    default:
                        throw new Exception("User Role Invalid.");
                    }

                    jsonResult.Add("result", 1);
                    jsonResult.Add("target", targetPath);
                    jsonResult.Add("message", "");
                    SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Success(SessionContext.User.ID.ToString()));
                    break;

                case AuthenticateManager.AuthenState.AuthenticationFail:
                    jsonResult.Add("result", 0);
                    jsonResult.Add("target", "");
                    jsonResult.Add("message", "Login Failed.");
                    SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(string.Format("{0} : {1}", idCard, nameEng)));
                    break;

                case AuthenticateManager.AuthenState.AlreadyLogin:
                    jsonResult.Add("result", 0);
                    jsonResult.Add("target", "");
                    jsonResult.Add("message", "Login Failed.");
                    SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(user.ID.ToString() + " : Login Attemp."));
                    break;

                default:
                    break;
                }

                WebLogger.Warn("End Authenticating");

                return(new JavaScriptSerializer().Serialize(jsonResult));

                #region old

                //Dictionary<string, object> jsonResult = new Dictionary<string, object>();
                //IList<SelfAuthenticatedUser> users = SessionContext.PersistenceSession.QueryOver<SelfAuthenticatedUser>().List();
                //IList<SelfAuthenticatedUser> user = users.Where(s => s.LoginName.ToLowerInvariant() == nameEng.ToLowerInvariant()
                //        && s.Person.OfficialIDNo == idCard
                //        && s.UserRoles[0].Role.Id == int.Parse(status)
                //        && !s.IsDisable
                //        && s.IsEffective).ToList();

                //if (0 < user.Count)
                //{
                //    if (user.Count != 1) { throw new Exception("User have more than one. System error."); }

                //    //if (!user[0].IsBuiltin)
                //    //{
                //    //    IList<iSabaya.UserSession> userSessions = SessionContext.PersistenceSession
                //    //        .QueryOver<iSabaya.UserSession>()
                //    //        .Where(us => us.User.ID == user[0].ID
                //    //            && us.SessionPeriod.To == iSabaya.TimeInterval.MaxDate)
                //    //        .List();

                //    //    if (userSessions.Any(u => u.User.ID == user[0].ID))
                //    //    {
                //    //        jsonResult.Add("result", 0);
                //    //        jsonResult.Add("target", "");
                //    //        jsonResult.Add("message", "Login Failed.");
                //    //        SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(userSessions[0].User.ID.ToString() + " : Login Attemp."));
                //    //        //SessionContext.StartFailedSession(null, idCard, Session.SessionID, "Login Attemp.");

                //    //        return new JavaScriptSerializer().Serialize(jsonResult);
                //    //    }
                //    //}

                //    BudgetConfiguration.CurrentConfiguration = GetConfiguration(SessionContext, SessionContext.MySystem.SystemID);
                //    SessionContext.StartNewSession(user[0], Session.SessionID);

                //    string targetPath = "";
                //    switch (user[0].UserRoles[0].Role.Id)
                //    {
                //        //case 1:
                //        //    targetPath = FullUrl("Government");//ส่วนราชการ
                //        //    break;
                //        case 2:
                //            targetPath = FullUrl("Budgetor");//ทำงบประมาณ
                //            break;
                //        case 3:
                //            targetPath = FullUrl("Evaluation");//เจ้าหน้าที่ประเมินงบ
                //            break;
                //        //case 4:
                //        //    targetPath = FullUrl("Admin");//ผู้ดูแลระบบ
                //        //    break;
                //        default:
                //            throw new Exception("User Role Invalid.");
                //    }

                //    jsonResult.Add("result", 1);
                //    jsonResult.Add("target", targetPath);
                //    jsonResult.Add("message", "");
                //    SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Success(SessionContext.User.ID.ToString()));
                //}
                //else
                //{
                //    jsonResult.Add("result", 0);
                //    jsonResult.Add("target", "");
                //    jsonResult.Add("message", "Login Failed.");
                //    SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail());
                //    //SessionContext.StartFailedSession(null, idCard, Session.SessionID, "Login Failed.");
                //}

                //WebLogger.Warn("End Authenticating");
                //return new JavaScriptSerializer().Serialize(jsonResult);

                #endregion old
            }
            catch (Exception ex)
            {
                WebLogger.Error(ex.GetAllMessages());

                Dictionary <string, object> jsonResult = new Dictionary <string, object>();
                jsonResult.Add("result", 0);
                jsonResult.Add("target", "");
                jsonResult.Add("message", ex.ToString());

                //SessionContext.StartFailedSession(null, idCard, Session.SessionID, ex.Message);

                SessionContext.Log(0, this.pageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(ex.Message));

                return(new JavaScriptSerializer().Serialize(jsonResult));
            }
        }
        protected override void OnReportGenerating(object sender, ReportGeneratingEventArgs e)
        {
            try
            {
                WorkTimeEstimateStorage storage = WorkTimeEstimateStorage.CreateInstance(UserUtil.getCurrentSchema());
                WorkTimeEstimateDataSet data    = new WorkTimeEstimateDataSet();
                XtraReport report = new XtraReport();

                if (IsSimpleRaportView())
                {
                    sortingPanel.Visible   = true;
                    searchingPanel.Visible = true;
                    rbAll.Enabled          = false;
                    rbMontaz.Enabled       = false;
                    rbObrobka.Enabled      = false;


                    string materialSortOrder = "";
                    string sizeSortOrder     = "";

                    if (!string.IsNullOrEmpty(dbMaterialSorting.Text))
                    {
                        materialSortOrder = dbMaterialSorting.Text;
                    }
                    if (!string.IsNullOrEmpty(dbSizeSorting.Text))
                    {
                        sizeSortOrder = dbSizeSorting.Text;
                    }


                    report = new WorkTimeEstimateXtraReportSimple(Page.Theme)
                    {
                        materialSortOrder = materialSortOrder, sizeSortOrder = sizeSortOrder
                    };

                    //overload for a flat DataSet
                    data = storage.GetWorkTimeEstimateToPrint(
                        UserUtil.getCurrentAppId(),
                        project.GetValueInt32().HasValue ? project.GetValueInt32().Value : 0,
                        departamentAll.GetValueString(), "rbAll", reportFilterParameter());
                }
                else
                {
                    if (rbAll.Checked)
                    {
                        report = new WorkTimeEstimateXtraReport(Page.Theme);
                        data   = storage.GetWorkTimeEstimateToPrint(
                            UserUtil.getCurrentAppId(),
                            project.GetValueInt32().HasValue ? project.GetValueInt32().Value : 0,
                            departamentAll.GetValueString(), "rbAll");
                    }
                    else if (rbMontaz.Checked)
                    {
                        report = new WorkTimeEstimateInstallationXtraReport(Page.Theme);
                        data   = storage.GetWorkTimeEstimateToPrint(
                            UserUtil.getCurrentAppId(),
                            project.GetValueInt32().HasValue ? project.GetValueInt32().Value : 0,
                            departamentInstl.GetValueString(), "rbMontaz");
                    }
                    else // rbObrobka
                    {
                        report = new WorkTimeEstimateWorkingXtraReport(Page.Theme);
                        //data = storage.GetWorkTimeEstimateWorkingToPrint(
                        data = storage.GetWorkTimeEstimateToPrint(
                            UserUtil.getCurrentAppId(),
                            project.GetValueInt32().HasValue ? project.GetValueInt32().Value : 0,
                            departamentWork.GetValueString(), "rbObrobka");
                    }
                }

                report.DataSource = data;
                e.Report          = report;
            }
            catch (Exception ex)
            {
                if (DbUserErrorUtil.IsUserError(ex))
                {
                    this.SetErrorStatus(
                        DbUserErrorUtil.GetErrorMessage(ex, this.GetGlobalResourceObject("FormControl", "error").ToString()));

                    e.Cancel = true;
                }
                else
                {
                    LOGGER.Error(ex);
                    throw ex;
                }
            }
        }
Пример #8
0
        public string Authentication(string idCard, string nameEng, string status)
        {
            try
            {
                SessionContext.PersistenceSession.Clear();
                WebLogger.Warn("Authenticating");
                var  jsonResult = new Dictionary <string, object>();
                User user       = null;
                BudgetConfiguration.CurrentConfiguration
                    = GetConfiguration(SessionContext, SessionContext.MySystem.SystemID);

                switch (AuthenticateManager
                        .Authenticate(SessionContext,
                                      SystemEnum.RiskAssessmentProjectOwnerSystem,
                                      idCard,
                                      nameEng,
                                      ref user))
                {
                case AuthenticateManager.AuthenState.AuthenticationSuccess:

                    SessionContext.StartNewSession(user, Session.SessionID);

                    var targetPath = "";
                    switch (user.UserRoles[0].Role.Id)
                    {
                    case 1:
                        targetPath = FullUrl("Government");        //ส่วนราชการ
                        break;

                    case 2:
                        targetPath = FullUrl("Budgetor");        //ทำงบประมาณ
                        break;

                    case 3:
                        targetPath = FullUrl("Evaluation");        //เจ้าหน้าที่ประเมินงบ
                        break;

                    case 4:
                        targetPath = FullUrl("Admin");        //ผู้ดูแลระบบ
                        break;

                    default:
                        throw new Exception("User Role Invalid.");
                    }

                    jsonResult.Add("result", 1);
                    jsonResult.Add("target", targetPath);
                    jsonResult.Add("message", "");
                    SessionContext.Log(0, PageID, 0, MessageException.AuthenMessage.Login, MessageException.Success(SessionContext.User.ID.ToString()));
                    break;

                case AuthenticateManager.AuthenState.AuthenticationFail:
                    jsonResult.Add("result", 0);
                    jsonResult.Add("target", "");
                    jsonResult.Add("message", "Login Failed.");
                    SessionContext.Log(0, PageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(string.Format("{0} : {1}", idCard, nameEng)));
                    break;

                case AuthenticateManager.AuthenState.AlreadyLogin:
                    jsonResult.Add("result", 0);
                    jsonResult.Add("target", "");
                    jsonResult.Add("message", "Login Failed.");
                    SessionContext.Log(0, PageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(user.ID.ToString() + " : Login Attemp."));
                    break;

                default:
                    break;
                }

                WebLogger.Warn("End Authenticating");

                return(new JavaScriptSerializer().Serialize(jsonResult));
            }
            catch (Exception ex)
            {
                WebLogger.Error(ex.GetAllMessages());

                var jsonResult = new Dictionary <string, object>();
                jsonResult.Add("result", 0);
                jsonResult.Add("target", "");
                jsonResult.Add("message", ex.ToString());

                SessionContext.StartFailedSession(null, idCard, Session.SessionID, ex.Message);
                SessionContext.Log(0, this.PageID, 0, "Login", "Fail : " + ex.Message);

                return(new JavaScriptSerializer().Serialize(jsonResult));
            }
        }