Example #1
0
        public object login(string userName, string password)
        {
            Dictionary <string, object> row = new Dictionary <string, object>();

            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            try
            {
                cls_User obj_usr = new cls_User();
                DataSet  ds      = new DataSet();
                ds = obj_usr.fn_Login(userName, password, 2);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DateTime expiresOn = DateTime.Parse(ds.Tables[0].Rows[0]["expiresOn"].ToString());

                    TimeSpan span = expiresOn - DateTime.Now;
                    double   i    = span.TotalSeconds;
                    if (expiresOn < DateTime.Now)
                    {
                        row.Add("Status", "User account is not active..");
                        row.Add("id", null);
                    }
                    else
                    {
                        row.Add("Status", "Success");
                        row.Add("id", ds.Tables[0].Rows[0]["ID"].ToString());
                    }
                }
                else
                {
                    row.Add("Status", "Wrong Credentials..");
                    row.Add("id", null);
                }
                return(serializer.Serialize(row));
            }
            catch (Exception e)
            {
                row.Add("Status", "Faliure");
                row.Add("Message", e.Message);
            }
            //  row.Add("Status", "Success");
            return(serializer.Serialize(row));
        }
        protected void btnLogin_Click(object sender, ImageClickEventArgs e)
        {
            cls_User obj_usr = new cls_User();
            DataSet  ds      = new DataSet();

            ds = obj_usr.fn_Login(txtbLoginName.Text, txtbPassword.Text, 2);
            if (ds.Tables[0].Rows.Count > 0)
            {
                DateTime expiresOn = DateTime.Parse(ds.Tables[0].Rows[0]["expiresOn"].ToString());

                TimeSpan span = expiresOn - DateTime.Now;
                double   i    = span.TotalSeconds;
                if (expiresOn < DateTime.Now)
                {
                    lblmsg.Text = "User account is not active..";
                }
                else
                {
                    Session["UserName"] = ds.Tables[0].Rows[0]["UserName"].ToString();
                    Session["loginid"]  = ds.Tables[0].Rows[0]["ID"].ToString();
                    Session["userID"]   = ds.Tables[0].Rows[0]["loginID"].ToString();
                    Session["role"]     = ds.Tables[0].Rows[0]["Role"].ToString();


                    if (ds.Tables[0].Rows[0]["Role"].ToString() == "1") // 1 is role id of superAdmin
                    {
                        Session["fk_CompanyID"] = 0;
                        Session["fk_OrgID"]     = 0;
                        Response.Redirect("dashboard.aspx");
                    }
                    else if (ds.Tables[0].Rows[0]["Role"].ToString() == "10") //10 is  role id of company admin
                    {
                        Session["fk_CompanyID"] = ds.Tables[0].Rows[0]["fk_CompanyID"].ToString();
                        Session["fk_OrgID"]     = 0;
                        Response.Redirect("dashboard.aspx");
                    }
                    else if (ds.Tables[0].Rows[0]["Role"].ToString() == "20") // 20 is role id of orgadmin user
                    {
                        Session["fk_CompanyID"] = 0;
                        Session["fk_OrgID"]     = ds.Tables[0].Rows[0]["fk_OrgID"].ToString();
                        Response.Redirect("dashboard.aspx");
                    }
                    else if (ds.Tables[0].Rows[0]["Role"].ToString() == "30") // 30 is role id of normal user
                    {
                        Session["fk_CompanyID"] = 0;
                        Session["fk_OrgID"]     = ds.Tables[0].Rows[0]["fk_OrgID"].ToString();
                        Response.Redirect("dashboard.aspx");
                    }
                    else if (ds.Tables[0].Rows[0]["Role"].ToString() == "50") // 30 is role id of normal user
                    {
                        Session["fk_CompanyID"] = ds.Tables[0].Rows[0]["ID"].ToString();
                        Session["fk_OrgID"]     = ds.Tables[0].Rows[0]["fk_OrgID"].ToString();
                        Response.Redirect("dashboard.aspx");
                    }
                }
            }
            else
            {
                lblmsg.Text = "Wrong Credentials..";
            }
        }