Welcome Guest, Not a member yet? Register   Sign In
dx auth - how to get user email
#1

[eluser]Frank Rocco[/eluser]
Hello,

How do I get the email address of the current logged in user in dx auth?

I tried:

$id = $this->dx_auth->get_user_id();
$query = $this->users->get_user_field($id,"email");

But I do not know if this works, do not know how to reference $query to get email.

Thanks in advance.
#2

[eluser]mdcode[/eluser]
While not as specific as dx auth, the following may give you the push in the right direction you need:

CONTROLLER:
Code:
$data['email'] = $this->model_name->get_email_address($id);

MODEL:
Code:
function get_email_address($id = '')
{
$this->db->select('email');
$this->db->from('users');
$this->db->where('id', $id);

$query = $this->db->get();

return $query->result();
}

While I'm going from memory (which isn't that great) from using my own auth library, and the code is not tested, it should hopefully give you enough information to help you get where you need to be.
#3

[eluser]Frank Rocco[/eluser]
Thanks for the tip.
There are a lot of auth libraries out there for CI.
I just wanted one that did roles and had pre-made forms to reduce coding time.

I am using CI 1.72, and notice some auth libraries might not work.
Dx Auth is a little over kill.

regards
#4

[eluser]mdcode[/eluser]
True, I started off by using Adam Griffiths auth library available somewhere on these forums, but it was a little too cumbersome for my needs and I could never get it integrating with any of my sites, so... I went searching and came across this tutorial:

Bramme.net Auth Library Tutorial

Which once the basics were down and the script was working, I went on modyfying things to include my own roles based permission set up which is being used for two of my websites.
#5

[eluser]123wesweat[/eluser]
hi frank,

I am looking for the same, haven't found a 'right' way but this works.

Code:
if an user is loggedin

$user_id = $this->dx_auth->get_user_id('username');
            $arrEmail=$this->_get_email($user_id);
            $data['email'] = $arrEmail->email;
    /* Utility functions */
    function _get_email($user_id)
    {
        $this->load->model('dx_auth/users');
        $emailArr = $this->users->get_user_field($user_id, 'email')->result();
        return $emailArr[0];
    }

There might be a better way




Theme © iAndrew 2016 - Forum software by © MyBB