<p>I found a solution using the <a href="https://github.com/pixelandtonic/ElementAPI" rel="nofollow">Element API</a> plugin, with the following endpoints config:</p>

<pre class="lang-php prettyprint-override"><code>&lt;?php
namespace Craft;

return [
    'endpoints' =&gt; [
        'user/info.json' =&gt; [
            'elementType' =&gt; 'User',
            'criteria' =&gt; [
                'id' =&gt; craft()-&gt;userSession-&gt;getId()
            ],
            'first' =&gt; true,
            'transformer' =&gt; function (UserModel $user) {
                return [
                    'email' =&gt; $user-&gt;email,
                    'image' =&gt; $user-&gt;getPhotoUrl('28')
                ];
            },
        ]
    ]
];
</code></pre>

<p>Now after saving a user I can just create an Ajax request to <code>/user/info.json</code> and get their info in response.</p>

CC BY-SA 3.0
2015-10-06T21:54:01.120Z
Hey Vitaliy, I just updated your question and answer to make them more clear for other people in the future. I also added `'first' => true` to your endpoint config, which is going to slightly alter the response format, making it more optimized for a single user response. You can see how a single-user response differs from multi-user by looking at the [Examples section](https://github.com/pixelandtonic/ElementAPI#examples) in the Element API docs.
Brandon Kelly
CC BY-SA 3.0
2015-10-04T20:18:52.280Z
2015-10-06T21:51:36.847Z
2015-10-06T21:51:36.847Z
Vitaliy  Badalov
<p>For the redirect I agree, I could not get it too from ajax response, so I just saved it before the ajax call.<br>
<code>var returnUrl = $("input[name='redirect']").val();</code></p>

<p>Then I can make the redirection :  </p>

<pre><code>.success(function(data) {
    if (data.success) {
        window.location.href = returnUrl;
    }
</code></pre>

<p>For the user's data could you precise what you want to do?</p>

CC BY-SA 3.0
2015-10-04T13:24:43.710Z
I on the contrary do not want to redirect the user. I update question.
Vitaliy  Badalov
CC BY-SA 3.0
2015-10-04T09:35:02.870Z
2015-10-04T09:35:02.870Z
migmaker
<p>I created an Ajax-based login form based on this gist: <a href="https://gist.github.com/keithmancuso/29e8446ec5fa66fb2b01" rel="nofollow">https://gist.github.com/keithmancuso/29e8446ec5fa66fb2b01</a>.</p>

<p>After the user has logged in, how can I get some info about them over Ajax?</p>

CC BY-SA 3.0
2015-09-28T11:25:40.127Z
I do not want to refresh the page for such a trifle
Vitaliy  Badalov
<users><ajax><current-user><plugin-elementapi>
How do I get the current user’s info over Ajax?
# How do I get the current user’s info over Ajax?

(Asked by: username_0 on 2015-09-27)

I created an Ajax-based login form based on this gist: <https://gist.github.com/keithmancuso/29e8446ec5fa66fb2b01>.

After the user has logged in, how can I get some info about them over Ajax?

**Tags:** users, ajax, current-user, plugin-elementapi
> **Comments:**
> **username_0**: I do not want to refresh the page for such a trifle  

---

## 2 answers

### Answer by username_0 on 2015-10-04. Score: 2 | Accepted answer

I found a solution using the Element API plugin, with the following endpoints config:
 [
        'user/info.json' => [
            'elementType' => 'User',
            'criteria' => [
                'id' => craft()->userSession->getId()
            ],
            'first' => true,
            'transformer' => function (UserModel $user) {
                return [
                    'email' => $user->email,
                    'image' => $user->getPhotoUrl('28')
                ];
            },
        ]
    ]
];

Now after saving a user I can just create an Ajax request to /user/info.json and get their info in response.

> **Comments:**
> **username_1**: Hey Vitaliy, I just updated your question and answer to make them more clear for other people in the future. I also added `'first' => true` to your endpoint config, which is going to slightly alter the response format, making it more optimized for a single user response. You can see how a single-user response differs from multi-user by looking at the [Examples section](https://github.com/pixelandtonic/ElementAPI#examples) in the Element API docs.  

---

### Answer by username_2 on 2015-10-04. Score: 3

For the redirect I agree, I could not get it too from ajax response, so I just saved it before the ajax call.
var returnUrl = $("input[name='redirect']").val();
Then I can make the redirection :  
.success(function(data) {
    if (data.success) {
        window.location.href = returnUrl;
    }

For the user's data could you precise what you want to do?

> **Comments:**
> **username_0**: I on the contrary do not want to redirect the user. I update question.  

---

