Get Current User details SharePoint

//Get current user details
currentUser = {};
$scope.getUser = function () {
getUserDetails("..", _spPageContextInfo.userId).done(function (result) {
var accountName = result.LoginName.split("|")[1],
image = "https://webmail.wp.corpshared.net/ecp/PersonalSettings/~/Download.aspx?Identity=" + result.Email + "&handlerClass=UserPhotoDownloadHandler&preview=false";
//image = 'https://my.ey.net:443/User%20Photos/Profile%20Pictures/' + accountName.split('\\')[0] + '_' + ((accountName.split('\\')[1]).split('.')).join('_') + '_MThumb.jpg';
currentUser.image = image;
currentUser.title = result.Title;
currentUser.Id = result.Id;
var email = result.Email;
emailCurrentuser = result.Email;

getUserAcountDetails('..', accountName).done(function (result) {
currentUser.sip = getArrayItemValueByKeyValuePair(result, 'Key', 'SPS-SipAddress').length > 0 ? getArrayItemValueByKeyValuePair(result, 'Key', 'SPS-SipAddress')[0].Value : email;
$scope.userdetails = currentUser;
$scope.$digest();
//lync.init();
});

});
}


function getUserAcountDetails(url, accountName) {
    var dfd = $.Deferred();
    $.ajax({
        url: url + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + accountName + "'",
        method: "GET",
        headers: {
            "Accept": "application/json; odata=verbose"
        },
        success: function (data) {
            dfd.resolve(data.d.UserProfileProperties.results);
        },
        error: function (data) {
            dfd.reject(JSON.stringify(data));
        }
    });
    return dfd.promise();
}

Comments