Results 1 to 11 of 11

Thread: Help Please

  1. #1
    Billywizz is offline Member
    Join Date
    Jan 2011
    Posts
    57
    Rep Power
    0

    Default Help Please

    Hi i have i website which allows users to log in and view other peoples profiles etc. i am trying to set up a process where one person can request someone else to be there friend, however quite stuck here is my problem:

    I add a row to my friend_requests table when my servlet is invoked which creates a new friend_Request_ID however in order to create the friend object to pass to the method that adds the row i need the ID of the current user logged which will be the requestor and the ID of the person who is being requested (the recipient). I think i have worked out how to get the recipient as i can just get the ID from the bean of the person whos profile i am on but really stuck on how to get the users_ID to represent the requestor?? so mainly:

    How can i get the user ID of the person that is currently logged in?

    Thanks

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    sorry but that incredibly long sentence isn't helpful to the fact you haven't given any code to debug

    p.s. your name is Willy wizz, haha

  3. #3
    Billywizz is offline Member
    Join Date
    Jan 2011
    Posts
    57
    Rep Power
    0

    Default

    LOL its not a debugging issue its a logical, how do i go about doing this. basically how would you go about getting the user ID of the person that is currently logged in to a website?

    im thinking maybe using a session but not reli sure how they work??

  4. #4
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    this would be a very simplified version as an example:

    Java Code:
    public class Users {
        private static final long userID;
        private String userPW;
        private String userName;
        //constructor
        Users (userPW,userName) {
            userID++;
            this.userName = userName;
            this.userPW = userPW;
        }
        //get and set methods
    }
    so when the user logs in, you do a search against their userName, and check if the combination of userName and userPW matches.... if it matches, you get the same user objects get method:

    thisUser.getUserID();

  5. #5
    Billywizz is offline Member
    Join Date
    Jan 2011
    Posts
    57
    Rep Power
    0

    Default

    Yes sorry, i already have the login sorted users can login fine but i have another method where i want to use the userID and the persons ID they want to add as a friend to insert a new record into the friend requests table and therefore need to get my current logged in userID to represent the column requestor but as the add friend link is on the other persons page i cant getParameter() as there is no form to get it from like there was in the login? I think i need to store it in a session variable so i can use it whenever i want? Is this the case?

    Sorry about this BAD post see my other post called sessions its abit more to the point hopefully :/

  6. #6
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    what is column requestor and what is getParameter for?? when a user logs in...you have their ID... you want to allow the user to press "Add Friend" on another users profile page, but isnt the profile page created dynamically from the userID (you would need the userID to search your Users object/table to get their other info) and when you create this Add Friend button it should be created with the users ID already in it, like the action should be something like:

    addFriend(viewer,930); where the number is the UserID and the viewer is the user who logged in.

    when you're talking about sessions maybe you're looking for how to write cookies? if you write a cookie it lasts the whole session so when the user logs in you store their ID in that text file

  7. #7
    Billywizz is offline Member
    Join Date
    Jan 2011
    Posts
    57
    Rep Power
    0

    Default

    column Requester is a column in a database table that contains friend_Request_ID, Requestor INT REFERENCES user_ID, and Recipient INT REFERENCES user_ID, this i what i want to add a row to when someone clicks add as friend a new friend_Request_ID is entered by adding one to the max, then i need to get the User currently loggen in who will be the requester, and the person whos page i am on will be the recipient_ID (I can get the recipient ID and Friend_Request_ID). So my website goes like this:

    1) HomePage - login or create account (click login)
    2) enterLog in details (loggon on and all info about user is got including userID)
    3) click button search for someone(enter someones username)
    4) search database WHERE the parameter in the form = username in the database (displayresults)
    5) click to go to this found persons page(link to getUser where this userID = userID in the database) display results
    6) click button to add as friend (but now how do i get the current logged in userID to represent the requester? i cannot get it now? as i am off the users page - do i need to store that information i get in part 2 somehow so that i can use it whenever?)

  8. #8
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    when the user logs in, and searches, and clicks a link to go to another page, the page should still be viewed as the user logged in. if you login to facebook and click on a friends page. you'll notice your userID is passed on as a parameter in the address bar on every page you visit. because each user must have their OWN view of things. if each user doesn't have their own view of things, then if you set your profile to friends only, how can you stop non-friends from viewing your details? the view is dependent on the viewer, its like an App rather than an open website once you log in. So the user ID must be passed around in parameters, or make another class to View/browse your website once logged in

  9. #9
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    so the flaw is, rather than switching pages, VIEW Page As Logged-in User

    i just logged in facebook to double check, its a little different now as my own ID is hidden, but when i click on another page it doesnt change from home.php:

    facebook.com/home.php#!/profile.php?id=FRIEND_ID

  10. #10
    Billywizz is offline Member
    Join Date
    Jan 2011
    Posts
    57
    Rep Power
    0

    Default

    ohh Ok so how can i pass around the ID on every page that i go to do i just keep passing it on to everypage using the getParameter(person_id) for every page i go to?

  11. #11
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    you need to make a new class, which is an application in its own sense. when the user logs in, it takes them to the app. the app allows the user to view pages and do functions. remember <html> is integrated into java so this should be easy.

    the main thing is that viewing is restricted. once you log in, you're stuck. whatever page you see, is an instance of that page with your permissions set.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •