0

I do have a profile page which is accessible just if the user has been logged in. In other words, if user calls: localhost:9595/profile, then the profile service/component checks the session and if the user is logged in or not.

If logged in, then I want to get its email from session and pre fill the username input field with the email.

My issue is how to get the username/email from the session and pre fill the username-field with it. Would it be done just with saving the session and getting the username as mentioned in this question and this one, or would it be different in my case? I am a kind of confused regarding what I get as response from the server:

{
    "username": "b43d74a8-9de4-4b06-b9b0-52d88808ba59",
    "universalId": "id=b43d74a8-9de4-4b06-b9b0-52d88808ba59,ou=user,o=cons,dc=org",
    "latestAccessTime": "2018-03-13T07:10:33Z",
    "maxIdleExpirationTime": "2018-03-13T07:40:33Z",
    "maxSessionExpirationTime": "2018-03-13T09:10:32Z"
}
k.vincent
  • 3,743
  • 8
  • 37
  • 74
  • That's a very strange and specific username. Are you by any chance using a library ? –  Mar 13 '18 at 13:24
  • Sorry, don't understand what you exactly mean with your question. Could please specify? – k.vincent Mar 13 '18 at 13:30
  • My username is `trichetriche`. Here, the username is `b43d74a8-9de4-4b06-b9b0-52d88808ba59`, and the fields are very specific : `universalId, maxSessionExpirationTime ...`. My question is, did you code those fields, or are you using a library or a framework ? –  Mar 13 '18 at 13:32
  • The username (input field in the form ui which passes an email to backend) is sent to the backend to login the user, and after that, the user is being redirected to the profile page with the session. And what I posted in my question is the answer of the server - I didn't code those fields and also not the backend for that. No framework or library. For the UI, I'am using Angular without any extra library or package. – k.vincent Mar 13 '18 at 13:39
  • Can you simply change the "server" (the backend, the API) to include/append this user's attribute in the response? – Christian Benseler Mar 13 '18 at 13:47
  • Unfortunately not... – k.vincent Mar 13 '18 at 13:52

1 Answers1

0

Be careful with the cross domain.

You should handle: "Access-Control-Allow-Origin", "http://localhost:9595" - server side.

If you handled CROS problem the following solution might help :

// some logic before
if(userLoggedIn){
    this.url = 'http://my-dummy-url.com';
    let headers = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({ headers: headers });
    options.withCredentials = true;

    return this._http.get(this.url, options)
        .map((response: Response) => {
             const mJson = response.json();
             console.log("the username we found is " + mJson.username);
        });
     } 

// some logic after this...
Achref Gassoumi
  • 1,035
  • 10
  • 20