Exemple #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         UserProfile UserProfileObj = new UserProfile();
         if (CookieProxy.Instance().HasKey("t"))
         {
             UserProfileObj.SetToken(CookieProxy.Instance().GetValue("t").ToString());
             // check if the current user is admin or not
             bool AuthAdminResponseObj = new Security(UserProfileObj).AuthenticateAdmin();
             if (AuthAdminResponseObj == false)
             {
                 CookieProxy.Instance().SetValue("LoginMessage", "Not Authorized, please login with correct credentials".ToString(), DateTime.Now.AddDays(2));
                 Response.Redirect("/signout.aspx", false);
             }
             else
             {
                 UserTemplate <IUserProfile> Template = new AdminUserTemplate();
                 userName.Text = Template.FetchParticularProfile(UserProfileObj).GetFirstName();
             }
         }
         else
         {
             Logger.Instance().Log(Warn.Instance(), new LogDebug("An attempt was made to access the admin panel but failed."));
             CookieProxy.Instance().SetValue("LoginMessage", "Not Authorized, please login with correct credentials".ToString(), DateTime.Now.AddDays(2));
             Response.Redirect("/signout.aspx", false);
         }
     }
     catch (NullReferenceException)
     {
         Logger.Instance().Log(Warn.Instance(), new LogDebug("Unable to authenticate the token, token invalid or not found"));
         CookieProxy.Instance().SetValue("LoginMessage", "Unable to authenticate, please login with correct credentails.".ToString(), DateTime.Now.AddDays(2));
         Response.Redirect("/signout.aspx", false);
     }
     catch (Exception ex)
     {
         Logger.Instance().Log(Warn.Instance(), ex);
         if (CookieProxy.Instance().HasKey("LoginMessage") == false)
         {
             CookieProxy.Instance().SetValue("LoginMessage", "An error occured while authenticating, this event has been logged".ToString(), DateTime.Now.AddDays(2));
         }
         Response.Redirect("/signout.aspx");
     }
 }
Exemple #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ApiAuthResponse AuthResponseObj = new ApiAuthResponse();

        try
        {
            UserProfile UserProfileObj          = new UserProfile(Token: CookieProxy.Instance().GetValue("t").ToString(), Email: Request.Form["e"].ToString());
            UserTemplate <IUserProfile> Profile = new AdminUserTemplate(UserProfileObj);
            APIResponse ResponseObj             = Profile.Add();
            AuthResponseObj.SetAPIResponse(ResponseObj);
            if (ResponseObj == APIResponse.OK)
            {
                // log the event
                Logger.Instance().Log(Info.Instance(), new LogInfo(Profile.FetchParticularProfile(UserProfileObj).GetEmail() + " added " + Request.Form["e"]));
            }
        }
        catch (Exception ex)
        {
            AuthResponseObj.SetAPIResponse(APIResponse.NOT_OK);
            Logger.Instance().Log(Fatal.Instance(), ex);
        }
        Response.Write(new JavaScriptSerializer().Serialize(AuthResponseObj));
    }