Ejemplo n.º 1
0
        public JObject AgentLogin(String connection, UDC.AgentLogin agentLoginObj)
        {
            string hashPassword = string.Empty;

            try
            {
                Press3.DataAccessLayer.Agent agentObject = new Press3.DataAccessLayer.Agent(connection);
                byte[] bytesBefore = Encoding.Unicode.GetBytes(agentLoginObj.Password);
                byte[] bytesAfter  = HashAlgorithm.Create("SHA1").ComputeHash(bytesBefore);
                hashPassword           = Convert.ToBase64String(bytesAfter);
                agentLoginObj.Password = hashPassword;
                DataSet ds = agentObject.AgentLogin(agentLoginObj);
                if (ds == null || ds.Tables.Count == 0)
                {
                    helper.CreateProperty(UDC.Label.MESSAGE, "No data returned from database");
                    helper.CreateProperty(UDC.Label.SUCCESS, false);
                }
                else
                {
                    if (ds.Tables.Count > 1)
                    {
                        if (Convert.ToBoolean(ds.Tables[1].Rows[0]["Success"]))
                        {
                            string     sessionId  = Guid.NewGuid().ToString();
                            HttpCookie SessCookie = new HttpCookie("Press3Cookie", sessionId);
                            SessCookie.HttpOnly = true;
                            SessCookie.Values.Add("LoginId", ds.Tables[0].Rows[0]["LoginId"].ToString());
                            SessCookie.Values.Add("AgentId", ds.Tables[0].Rows[0]["Id"].ToString());
                            SessCookie.Values.Add("AccountId", ds.Tables[0].Rows[0]["AccountId"].ToString());
                            SessCookie.Values.Add("RoleId", ds.Tables[0].Rows[0]["RoleId"].ToString());
                            SessCookie.Values.Add("AgentName", ds.Tables[0].Rows[0]["Name"].ToString());
                            HttpContext.Current.Response.Cookies.Add(SessCookie);
                            // StudioController studioControllerObj = new StudioController();
                            // studioControllerObj.ManagerDashBoardCounts(connection, Convert.ToInt32(ds.Tables[0].Rows[0]["AccountId"]), "AgentLogin");
                        }
                    }
                    helper.ParseDataSet(ds);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Exception In AgentLogin " + ex.ToString());
            }
            return(helper.GetResponse());
        }