Exemple #1
0
        public string LogOn(string username, string password)
        {
            ResultData rs        = null;
            bool       passLogon = true;

            try
            {
                LoggingHelper.Debug("Start Logon");
                //Put verify code for USER
                SessionInfo sessioninfo = null;
                sessioninfo = UserUIP.LogOn(username, password);

                if (sessioninfo == null)
                {
                    LoggingHelper.Debug(username + " unsuccessfully logged in.");
                    Tracing.WriteLine(Tracing.Category.Trace, username + " unsuccessfully logged in.", TraceLevel.Info, Guid.Empty, Guid.Empty);
                    rs        = new ResultData(new Exception(username + " unsuccessfully logged in."), username + " unsuccessfully logged in.");
                    passLogon = false;
                }
                else
                {
                    // We need to keep token here.
                    FormsAuthentication.SetAuthCookie(username, false);

                    // Add a cookie here so we can retrieve later.
                    HttpCookie cookie = new HttpCookie(AppSettingName.TOKEN);
                    cookie.Value = SessionInfoSerializer.SessionInfoToString(sessioninfo);
                    Context.Response.Cookies.Add(cookie);

                    AddUsernameToCookie(sessioninfo);

                    // Check User Active
                    if (!sessioninfo.IsActive)
                    {
                        LoggingHelper.Debug(username + " has been inactive");
                        Tracing.WriteLine(Tracing.Category.Trace, username + " has been inactive", TraceLevel.Info, Guid.Empty, sessioninfo.CurrentUserId);
                        //rs = new ResultData(new Exception(username + " has been inactive"), username + " has been inactive");
                        //passLogon = false;
                    }
                }
                if (passLogon)
                {
                    LoggingHelper.Debug(username + " successfully logged in.");
                    Tracing.WriteLine(Tracing.Category.Trace, username + " successfully logged in.", TraceLevel.Info, Guid.Empty, sessioninfo.CurrentUserId);
                    rs = new ResultData("Success");
                }
                return(rs.ToString());
            }
            catch (Exception ex)
            {
                rs = new ResultData(ex);
                return(rs.ToString());
            }
        }
Exemple #2
0
        public string LogOn(string username, string password)
        {
            ResultData rs        = null;
            bool       passLogon = true;

            try
            {
                LoggingHelper.Debug("Start Logon");
                //Put verify code for USER
                SessionInfo sessioninfo = null;
                sessioninfo = UserUIP.LogOn(username, password
                                            , Context.Request.UserHostAddress
                                            , Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings[AppSettingName.AD_LOGIN]));

                if (sessioninfo == null)
                {
                    LoggingHelper.Debug(username + " unsuccessfully logged in.");
                    Tracing.WriteLine(Tracing.Category.Trace, username + " unsuccessfully logged in.", TraceLevel.Info, Guid.Empty, Guid.Empty);
                    rs        = new ResultData(new Exception(username + " unsuccessfully logged in."), username + " unsuccessfully logged in.");
                    passLogon = false;
                    ShowErrorMessage(username + " unsuccessfully logged in.");
                }
                else
                {
                    //Additional information for overwrite limit
                    sessioninfo.PCEOverwrite     = ConfigurationManager.AppSettings[AppSettingName.PCE_OVERWRITE].ToString() == "1" ? true : false;
                    sessioninfo.SETOverwrite     = ConfigurationManager.AppSettings[AppSettingName.SET_OVERWRITE].ToString() == "1" ? true : false;
                    sessioninfo.CountryOverwrite = ConfigurationManager.AppSettings[AppSettingName.COUNTRY_OVERWRITE].ToString() == "1" ? true : false;


                    // We need to keep token here.
                    FormsAuthentication.SetAuthCookie(username, false);

                    // Add a cookie here so we can retrieve later.
                    HttpCookie cookie = new HttpCookie(AppSettingName.TOKEN);
                    cookie.Value = SessionInfoSerializer.SessionInfoToString(sessioninfo);
                    Context.Response.Cookies.Add(cookie);

                    AddUsernameToCookie(sessioninfo);

                    // Check User Active
                    if (!sessioninfo.IsActive)
                    {
                        LoggingHelper.Debug(username + " has been inactive");
                        Tracing.WriteLine(Tracing.Category.Trace, username + " has been inactive", TraceLevel.Info, Guid.Empty, sessioninfo.CurrentUserId);
                        rs = new ResultData(new Exception(username + " has been inactive"), username + " has been inactive");
                        //passLogon = false;
                        ShowErrorMessage(username + " has been inactive");
                    }
                }
                if (passLogon)
                {
                    LoggingHelper.Debug(username + " successfully logged in.");
                    Tracing.WriteLine(Tracing.Category.Trace, username + " successfully logged in.", TraceLevel.Info, Guid.Empty, sessioninfo.CurrentUserId);
                    rs = new ResultData("Success");

                    Response.Redirect("Main.aspx?type=logon");
                }
            }
            catch (Exception ex)
            {
                rs = new ResultData(ex);
                //return rs.ToString();
                ShowErrorMessage("Error::" + ex.Message);
            }
            return(rs.ToString());
        }