Craft 3 -get user id and username - authentication

I'm using craft 3 Pro to make a website where users have a private area.
Users register and when login happens they are redirected to a page in the private area with respective info about that user.
When i use {% requireLogin %} with {{ currentUser.id }} craft 3 outputs the ID of the user that has active login in the CP (control panel).
But what i need is the ID of the user that made login in the frontend to access private area and not user ID that is logged in CP.
I'm reading craft 3 docs but didn't find the answer i'm looking for.
Any suggestions?

Craft does not make difference between CP and SITE users. There are only permissions to allow for a user to access the Control Panel.
However you can acces the basic user object with
craft.app.user That means the logged in user id is craft.app.user.id
If you want to access the User element to get the values of the custom fields you assigned to the users then
craft.app.user.identity and craft.app.user.identity.yourCustomField
What you need is to differentiate Admins from Regular users:
{% set userGroups = craft.app.user.identity.getGroups() %}
If userGroups contains the Admin user group, your user...is an admin clearly
Also there is a bunch of methods and properties for the identity object here:
https://docs.craftcms.com/api/v3/craft-elements-user.html#public-properties
Dig in!

Related

Basecamp 3 API : How to get comments created by the authorized user?

I am in the process of integrating my webapp with Basecamp 2 (solved, see edit) and 3, and I want to get all of the comments for a todo item for the authorized user.
First I make a call to https://launchpad.37signals.com/authorization.json which returns json that includes the user's identity, something like {"identity":{"id":99999999, ..... }}.
Then I make a call to the URL to get the comments for the item in question and go through them one by one matching the identity.id from above (99999999) with the creator.id for the comment.
The problem is, they don't match! I am working with one Basecamp2 project and one Basecamp3 project. When testing, using comments I wrote, Basecamp2 and Basecamp3 each have different values for creator.id (even though I wrote both comments!), and neither of them match the identity.id from authorization.json.
How do I link them to find which comments were made by the authorized user
Thanks
EDIT: I figured it out for Basecamp2 - I need to get /people.json which has a mapping from the identity_id of each user to the id for that user in that project. Still not sure how to do it for Basecamp3, which does not include identity_id in people.json!
The correct way to do this for Basecamp2 is to get:
https://basecamp.com/{project_id}/api/v1/people/me.json - the id node contains the id of the authorized user for project {project_id}.
for Basecamp3:
https://3.basecampapi.com/{project_id}/my/profile.json - the id node contains the id of the authorized user for project {project_id}.

How to modify laravel 5.6 login behaviour? How to add more fields for logging along with email and password?

Laravel has 2 fields in its auth to help user login i.e email and password. I have added another field(hidden field) in the login blade to pass a random number along with a password and email.
In my eloquentuserprovider.php i am grabbing $credentials[‘password’] and $credentials[‘email’] like this but when I write $credentials[‘hidden’] I get an error saying ‘undefined index hidden’.
So my question is how should I add other fields along with email and password to validate the user
I am writing all my validation logic in eloquentuserprovider.php

How to get user information from hippo via HST

I'm evaluating the hippo cms,
after add hst-security as a dependence ,so public site need login, but how can I fetch the login user's detail information like email and something else.
I used HstRequest.getUserPrincipal ,but only get the username.
and tried to write a query "SELECT_USER_QUERY = "SELECT * FROM hipposys:user"
but only get a user 'liveuser', after login with admin.
so , Anyone can help me ,how can I get the detail info?
You can do this:
final User user = JcrSessionUtils.getHippoSession(request.getRequestContext().getSession()).getUser();
user.getEmail();
user.getLastLogin()

MVC user's full name in Url, how to handle duplicates

I want to setup the following url in my MVC4 website, using the user's full name in the url:
http://www.myapp.com/profile/steve-jones
I have setup the following route in Global.asax:
routeCollection.MapRoute(
"profile", "profile/{userName}",
new { controller = "myController", action = "profile", userName = string.Empty
});
And I can take the parameter 'steve-jones' and match it to a user with matching name. My only problem though is, what if there is more than one 'Steve Jones', how can I handle this?
Does anyone know of a workaround/solution to this so that I can use a user's full name as part of the url and still be able to retrieve the correct user in the controller method?
Am I forced into including the user's id with the url (something that I do not want to appear)?
The usual way of handling this is by appending a number when creating the profiles. So if "steve-jones" is already a name in the database, then make the user's display name "steve-jones2". You basically have to insist that all profile urls are unique, which includes updating any existing database and account creation code.
Alternatively (and/or additionally), if two same names are found then have the script reroute to a disambiguation page where the user is presented with links and snippet of profile info of the many existing Steve Joneseses so they can go to the full correct profile.
Another way of handling it is by giving all user profiles an additional numeric code on the end. At my university all logins are based on name, so they give everyone pseudo-random 3-digit extensions so that they are safe as long as they don't get 1000 people with the exact same names :)
Some people might be happier being steve-jones-342 if there is no steve-jones or steve-jones1, if you're concerned.

Retrieving Interest/Page information out of facebook

Im wondering if there is anyway to interogate facebook data on user interests. i.e. Retrieve the following data sets:
What are the most like interests/Pages on facebook?
Retreive the current users facebook interest and also their friends interests?
Really want to know if we can get facebook global interest/like data and than also if the user connects their facebook account to the site than we can also retrieve their interest data.
Thanks in advance
So you want to implement something like http://www.socialbakers.com/ ?
To get 1) you'd have to periodically poll the API for the public fan count of a known set of page IDs to see the current fan counts ( i think this is what socialbakers do)
To get 2, get the user_likes and friend_likes extended permissions from your users and access the /likes connection of the users whose likes you want to read
Yes you can retrieve user interests from facebook. You just need to include the user_interests permission required in your jsp page.
https://developers.facebook.com/tools/explorer/
If you are using spring social you can generate your own url for /me/interests:
URIBuilder uriBuilder1 = URIBuilder.fromUri(facebook.GRAPH_API_URL + "me" +"/interests");
String s = facebook.restOperations().getForObject(uriBuilder1.build(), String.class);