예제 #1
0
    protected void imgBtnLogin_Click(object sender, ImageClickEventArgs e)
    {
        //mjaved.sim.CommonLib Verifying User and creat its cookie

        SimplicityCommLib.DataSets.Common.UsersTableAdapters.UsersTableAdapter userTA = new SimplicityCommLib.DataSets.Common.UsersTableAdapters.UsersTableAdapter();
        IEnumerator<SimplicityCommLib.DataSets.Common.Users.UsersRow> ieUser = userTA.GetUserByEmail(txtEmail.Text).GetEnumerator();
        if (ieUser.MoveNext())
        {
            if (ieUser.Current.Password.Equals(Utility.GetMd5Sum(txtPassword.Text)) && ieUser.Current.FlgVerified)
            {
                // Cookie Implementation
                HttpCookie Cookie = new HttpCookie(WebConstants.Cookies.UserLoginSession);
                Cookie.Value = System.Guid.NewGuid().ToString();
                Cookie.Expires = DateTime.Now.AddMinutes(Constants.Configuration.SessionTimeoutInMinutes);
                Response.Cookies.Add(Cookie);

                SimplicityCommLib.DataSets.Common.SessionsTableAdapters.SessionsTableAdapter sessionTA = new SimplicityCommLib.DataSets.Common.SessionsTableAdapters.SessionsTableAdapter();
                sessionTA.Insert(System.Guid.NewGuid().ToString(), ieUser.Current.UserId, DateTime.Now, DateTime.Now.AddMinutes(Constants.Configuration.SessionTimeoutInMinutes), Request.UserHostAddress);

                //Cache.Insert("UserLoginSession", iEnumUser.Current.UserId, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(20));

                if (Session[WebConstants.Session.RETURN_URL] != null)
                {
                    Response.Redirect((string)Session[WebConstants.Session.RETURN_URL]);
                }
                else
                {
                    Response.Redirect("~/pages/UserHome.aspx");
                }
            }
            else
            {
                SetErrorMessage();
            }
        }
        else
        {
            SetErrorMessage();
        }
    }
 public SimplicityCommLib.DataSets.Common.Users.UsersRow GetLoggedInCustomer()
 {
     if (HttpContext.Current.Request.Cookies[WebConstants.Cookies.UserLoginSession] != null)
     {
         string sessionId = HttpContext.Current.Request.Cookies[WebConstants.Cookies.UserLoginSession].Value;
         if (sessionId != null && sessionId.Length > 0)
         {
             SimplicityCommLib.DataSets.Common.SessionsTableAdapters.SessionsTableAdapter sessionTA = new SimplicityCommLib.DataSets.Common.SessionsTableAdapters.SessionsTableAdapter();
             IEnumerator<SimplicityCommLib.DataSets.Common.Sessions.SessionsRow> ieSession = sessionTA.GetSessionByUID(sessionId).GetEnumerator();
             if (ieSession.MoveNext())
             {
                 SimplicityCommLib.DataSets.Common.UsersTableAdapters.UsersTableAdapter userTA = new SimplicityCommLib.DataSets.Common.UsersTableAdapters.UsersTableAdapter();
                 IEnumerator<SimplicityCommLib.DataSets.Common.Users.UsersRow> ieUser = userTA.GetUserById(ieSession.Current.UserId).GetEnumerator();
                 if (ieUser.MoveNext())
                 {
                     return ieUser.Current;
                 }
             }
         }
     }
     return null;
 }