Get username in magnolia - magnolia

I am using the following command to get the username in a custom magnolia class:String userName = MgnlContext.getInstance().getJCRSession("website").getUserID();
Instead of getting the name of the user who is signed on in magnolia when the command was triggered I am getting admin for the value. How can I get the real user name - the one who signed on to magnolia?

Actually to get current user, what you want is to either inject MgnlContext or get it via MgnlContext.getInstance() call.
Once you have context, you call ctx.getUser().getName() to get current user name.

You can inject info.magnolia.cms.security.SecuritySupport to your class and use
info.magnolia.cms.security.SecuritySupport#getUserManager()
afterwards, you are exposed to plenty of utility method that one can fetch all users or users by group etc.

Related

Can't validate email token when calling Accounts.sendVerificationEmail a second time

I installed a process of email address verification using Meteor Accounts. It works fine, but when Accounts.sendVerificationEmail() is called a second time, the Account.verifyEmail() method always refuse with a 403: Verify email link expired when called on the new token.
The email verification token set in Meteor.users by the first call to Accounts.sendVerificationEmail() is not changed when calling that method again: It's still the link sent with the first email that will work.
I can't find any info related to this in the Meteor documentation or on the internet. Is there something to do before beeing able to call Accounts.sendVerificationEmail() a second time (like cleanup or something?).
I had the same issue implementing the resend link to my website. I got around this by removing all the previous verficationTokens.
Here are two methods of applying a fix to this problem:
This is the preferred method if you already have an active database with n amount of users having trouble verifying their accounts. Place this code in a separate Meteor.call() method after you call the Accounts.sendVerificationEmail() method:
Meteor.users.update({_id: Meteor.userId()}, {'$push': services.email.verificationTokens": {$each: [], $slice: -1}}});
This will empty all the other tokens except for the last token created by the latest call to Accounts.sendVerificationEmail() method.
This method may be quicker for implementing newer projects or when implementing meteor-accounts in a new project. Similar to step 1) place this code in a new Meteor.call() method and call it after calling Accounts.sendVerificationEmail() method:
Meteor.users.update({_id: Meteor.userId()}, {'$pop': {"services.email.verificationTokens": -1}});
This will pop the first entry of the verificationTokens and thus the only entry is left with the latest token generated in Accounts.sendVerificationEmail() method.
Hope this helps.
When you use sendVerificationEmail(), a new entry appears in users collection : 'services.email.verificationTokens' and you'll see in 'emails.[x].verified' is false.
When you use verifyEmail(), the 'emails.[x].verified' go to true, and values in 'services.email.verificationTokens' disappear. So, if you try to use a second time verifyEmail(), it can't because email still verified and verification token is delete.
If you send a second time sendVerificationEmail() with a new token, the new link allows you to use verifyEmail() without error message.

How to pass user authentication of a private dataset through SODA API?

I need to access a private data set in socrata using SODA API. Suppose below link is the data set
https://data.cityofchicago.org/resource/xxxx-xxx.json
I get the following error when try this.
"error" : true,
"message" : "You must be logged in to access this resource"
I have valid credentials to access the data set. But how can I pass it through SODA API calls?
I tried the below code but it doesn't work.
https://data.cityofchicago.org/resource/xxxx-xxx.json?$username='myname'&$password='pwd#123'
You'll need to use either HTTP Basic or OAuth 2.0 to authenticate. We have details on how to do that on the developer portal.
Make sure you also provide an application token, as detailed in those docs.
You need to pass Secret-Token and AppToken with the query string.
How to Get secret Token
Log in to your portal and select "Create new Application"
Enter https://data.cityofchicago.org/resource/xxxx-xxx.json in the "website" field.
Save it.
Go to "Manage" and get your AppToken and SecretToken from under "Manage".
Now, pass the app token and secret token in the URL according to socrata developer document syntax:
https://sandbox.socrata.com/oauth/access_token
?client_id=YOUR_AUTH_TOKEN
&client_secret=YOUR_SECRET_TOKEN
&grant_type=authorization_code
&redirect_uri=YOUR_REDIRECT_URI
&code=CODE
I am also looking for an answer for the same question. After passing the app token I can access public DB but can not access Private DB.

Triggering a function when administrator enables a user in Sitecore

I'm trying to do a web application in which the user creates a account in the /extranet domain and its disabled initially.
When the sitecore admin enables the user account an function should be triggered so that a mail can be sent to the user, But i'm not finding any solution to trigger the code.
This is the code i have used to create the user in /extranet
Membership.CreateUser(mailId, password, mailId, "question", "answer", false, out status);
Well, there's a command that gets executed (<command name="usermanager:enable" type="Sitecore.Shell.Framework.Commands.UserManager.Enable,Sitecore.Kernel"/>) - which you can find in the Commands.config file in the App_Config folder - when you click on the Enable button, so you could override that with your own code (don't forget to also run that Enable functionality of course.
Please refer:
http://techmusingz.wordpress.com/2014/06/15/notify-sitecore-user-on-account-enable/
for a complete example of overriding the corresponding command.
You will need to replace
<command name="usermanager:enable" type="Sitecore.Shell.Framework.Commands.UserManager.Enable,Sitecore.Kernel"/>
with <command name="usermanager:enable" type="Sitecore72.Classes.EnableUserNotify, Sitecore72"/>
You could use the reflected code from Sitecore.Kernel.dll, and append your logic for notification in the Run method - where args.IsPostBack is true, after the user profile has been updated (user.IsApproved = true;)
This would enable you to retain the message boxes as implemented by sitecore and add the custom functionality you need as well.

How to check user status when login into wordpress

Could you please advice me how to check user status upon login?
I have added a new field named user_flag in wp_users table to control user status. user_flag has value of active or deactivate.
I want to check this field's value when user logs in.
if value is active, then user can proceed login,
but if value is deactivate, then user can not login, and a message will be displayed to notify user that his account is deactivated and he need to contact admin to re-activate account for him to be able to login.
I looked at wp-login.php file but had no idea where to write code to check above logic, could you please advice me where to check user_flag at login time?
Thank you so much.
Stop trying to modify core code and learn to use the pluggable architecture. Also stop modifying the core database tables. You can store additional fields for users in the usermeta table with add_user_meta and retrieve them with get_user_meta. If you start modifying core code and database tables, you will never be able to upgrade wordpress.
To answer your question, use something like the following in functions.php
add_filter('wp_authenticate_user', function($user) {
if (get_user_meta($user->ID, 'user_flag', true) == 'active') {
return $user;
}
return new WP_Error('Account Not Active...');
}, 10, 2);
See https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_authenticate_user

Twitterizer.TwitterUser.IsFollowing returns null

I am using Twitterizer to integrate Twitter into my ASP.NET app. After authenticating the user I am using following code to see if the authenticated user is following a specific user:
Twitterizer.TwitterUser followed = new Twitterizer.TwitterUser();
followed.ScreenName = tw_current_like;
bool? Following = followed.IsFollowing;
However Following.HasValue is always false. Am I missing something?
As I stated on the forums. Instantiating TwitterUser will not fetch any data from Twitter.
Also, the Twitter API is spotty in how/when it supplies the following indicator. You can use TwitterFriendship.Show(OAuthTokens, decimal/string) to query details about the relationship between the authenticated user and another user.

Resources