protected void Page_Load(object sender, EventArgs e)
    {
        List <IUserProfile> UserList = null;

        try
        {
            UserProfile UserProfileObj = new UserProfile();
            UserProfileObj.SetToken(CookieProxy.Instance().GetValue("t").ToString());
            UserTemplate <IUserProfile> Profile = new NormalUserTemplate(UserProfileObj, Request.Form["s"]);
            UserList = Profile.FetchList();
            if (UserList == null)
            {
                CookieProxy.Instance().SetValue("LoginMessage", "Unable to authenticate the token, please relogin or check logs", DateTime.Now.AddDays(2));
            }
            Logger.Instance().Log(Info.Instance(), new LogInfo(new AdminUserTemplate().FetchParticularProfile(UserProfileObj).GetEmail() + " searched for user " + Request.Form["s"]));
        }
        catch (Exception ex)
        {
            CookieProxy.Instance().SetValue("LoginMessage", "An Error occured while processing the request, please check logs", DateTime.Now.AddDays(2));
            Logger.Instance().Log(Warn.Instance(), ex);
        }
        finally
        {
            Response.Write(new JavaScriptSerializer().Serialize(UserList));
        }
    }
Exemple #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //get the database version
            try
            {
                string DBVersionString = DBVersion.GetDBVersion;

                if (new MaintenanceMode().IsMaintenanceModeEnabled() == APIResponse.OK)
                {
                    if (Page.TemplateControl.AppRelativeVirtualPath != "~/Login.aspx")
                    {
                        CookieProxy.Instance().SetValue("LoginMessage", new SettingsFromDB().FetchSettingsFromDB(new Settings("LOGIN_MAINTENANCE_MESSAGE")).GetSettingsValue(), DateTime.Now.AddDays(2));
                        Response.Redirect("/signout.aspx?r=/Login", false);
                    }
                }

                // here t is the token (if the user has logged in once from this browser)
                UserProfile UserProfileObj = new UserProfile();
                if (CookieProxy.Instance().HasKey("t"))
                {
                    UserProfileObj.SetToken(CookieProxy.Instance().GetValue("t").ToString());
                    bool response = new Security(UserProfileObj).AuthenticateUser();
                    if (response == true)
                    {
                        loginLabel.Visible    = false;
                        registerLabel.Visible = false;
                        userProfile.Visible   = true;
                        UserTemplate <IUserProfile> Template = new NormalUserTemplate();
                        userName.Text = Template.FetchParticularProfile(UserProfileObj).GetFirstName();
                    }
                    else
                    {
                        // remove the cookie
                        CookieProxy.Instance().RemoveKey("t");
                        loginLabel.Visible    = true;
                        registerLabel.Visible = true;
                        userProfile.Visible   = false;
                    }
                    SessionProxy.Instance().SetValue("USER.AUTHENTICATED", response, DateTime.Now);
                }
                // load the menu
                LoadMasterMenu();
            }
            catch (Exception ex)
            {
                Logger.Instance().Log(Fatal.Instance(), ex);
                Response.Redirect("~/ErrorPages/Error.aspx?e=500", true);
            }
        }
    }
    protected void RegisterButton_Click(object sender, EventArgs e)
    {
        string FirstName = firstName.Value;
        string LastName  = lastName.Value;
        string Email     = email.Value;
        string Password  = password.Value;

        // now get all the parameters via post
        try
        {
            UserProfile UserProfileObj = new UserProfile();
            UserProfileObj.SetFirstName(FirstName);
            UserProfileObj.SetLastName(LastName);
            UserProfileObj.SetEmail(Email);
            UserProfileObj.SetPassword(Password);
            UserProfileObj.SetRoleType("NORMAL");
            UserTemplate <IUserProfile> NormalUserTemplate = new NormalUserTemplate(UserProfileObj);
            APIResponse response = NormalUserTemplate.Add();
            if (response == APIResponse.OK)
            {
                // get the token
                List <string> Token  = new Security(UserProfileObj).GetTokenList();
                string        sToken = Token[Token.Count - 1].ToString();
                CookieProxy.Instance().SetValue("t", sToken, DateTime.Now.AddYears(1));
                Response.Redirect("/Products");
            }
            else
            {
                SetWarningLabel("Email already exists, please register with different email");
            }
        }
        catch (MySql.Data.MySqlClient.MySqlException mse)
        {
            if (mse.Number == 1062)
            {
                SetWarningLabel("Email already exists, please register with different email");
            }
            else
            {
                SetWarningLabel("An error occured while connecting to tthe DB, this event has been logged");
            }
        }
        catch (Exception)
        {
            SetWarningLabel("An error occured, please try again later<br> This event has been logged");
            registerButton.Visible = false;
        }
    }