I'm using django-registration which somehow stopped working the way it should work. I'm completely lost on this and have no idea where to start looking for the error.
So what happens is, that whenever a user clicks on the activation link, he gets the activation.html template. Which should only be shown when there was an error.
But actually there is no error. The user gets activated and can log in.
Any thoughts on this will be greatly appreciated.
First of all, the subject of your post and the actual description are conflicting. The subject says django-registration always fails to activate the user, but then in your description you say the user gets activated and can log in. Which is it?
Secondly, clicking on the activation link should always send the user to activate.html. You will have a variable called account on that page. If the activation was successful, account will be populated with the User object, otherwise it will be False.
There is a big difference between 0.7 and 0.8:
in 0.7:
registration/activate.html is displayed when a user attempts to
activate his/her account.
in 0.8
registration/activate.html
Used if account activation fails.
Debugging registration.views.activate showed: if the success_url isn't set,
the backend.post_activation_redirect method is called. If you're using the default backend, that returns an empty context without the account variable which is queried in the template.
The solution could be to overwrite the default backend.
The only problem is that you cannot pass any objects to views over a redirect. Hence, you cannot pass the account to the template context. You could do it with get params if wanted to.
I decided to just change the activation template and remove the condition.
Related
I am using Django allauth for authentication to my rest api. I have the whole process working as expected (login, registration, password reset) with email confirmation ..etc.
My question is when a user register the user receives an email with the link that user need to click and confirm to get access to the website. However, i want to use allauth but instead of a link I want a randomly generated activation code (example: 123456). That user can input in a form to confirm.
Allauth currently doesn't support this. You could open up an issue asking for the feature to be implemented, but considering that there's really no obvious advantage of using both systems, I doubt this would be accepted.
Is there a reason why the link method doesn't work for you, but this does? If so, maybe there's some workaround that could work?
Here's a possible workaround (albeit a very complicated one):
Write a template tag that would trim out the website part (ex example.com/confirm/ out of example.com/confirm/sdafsdagfsagfsdafasdfsafgfdsg), so that only the actual code is sent to the user in the email
Make a form that would accept this code, and, on submission, reconstruct the url back to its original state, and go to that url, effectively activating the account. You would almost definitely need to write custom javascript for this.
I am looking to implement django-registration for a project but am not sure if it will work out of the box for this use case. I am creating users as soon as I have their e-mail address (whether or not they actually are creating an account). At some time later those same users will try to register for an actual account and set a password, but the activation link will fail if the time ACCOUNT_ACTIVATION_DAYS has expired. Since I have separated the times at which someone actually gets a user versus when they are actually registered, I would ideally like to re-activate the user account.
I have looked through the docs and the source, but don't see any methods to re-activate the account or reset the activation key. Is there any solution to this built in?
Thanks!
I am using django-allauth to handle user registration in my site. I noticed a strange behavior. Let's say I register a new user in the site. That user get's a new email with a link to click. When the user clicks that link it takes him in the confirm page. There the user clicks the confirm button and users email is confirmed.
The problem is that as as a side effect the user is also logged in. I don't want that. This only happens only the first time I visit that page. If I visit that page again and confirms the email the user does not log in automatically.
My question is how can I prevent the user log in even in the first time he confirms the email. I searched the documentation but couldn't not find any setting to prevent this. Also I looked in the source code of ConfirmEmailView and I can't see a way to turn off this behavior besides manually commenting this line
resp = self.login_on_confirm(confirmation)
Update:
I think I found a workaround to the problem without having to fork or whatever. I just copied that class in my own views file trying to make sure I also imported all the other dependencies that are needed. Then I just deleted that call on login and the function that it calls. I hope I did a good job with that. After that in my urls.py, right before the imports for allauth, I copied the line that is used for confirm-email and redirected it to my own view. And now it looks like this
url(r'^accounts/confirm-email/(?P<key>\w+)/$', 'userprofile.views.confirm_email',
name="account_confirm_email"),
Seems a bit hackish but it seems to work well. I hope someone comes up with a better solution.
There is an option on the configuration ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION. It is True by default. Set it to False.
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = False
looking at the ConfirmEmailView from here one can see that login is done only if LOGIN_ON_EMAIL_CONFIRMATION is true. In order to prevent login on email confirmation you should set LOGIN_ON_EMAIL_CONFIRMATION to False in settings.py.
Currently, the below FB.api function is invoked on a click event and posts a user story on the user's timeline (the FB app is in sandbox mode right now and the user story is still pending review):
FB.api( // creating the user story
'/userid/mynamespace:myaction',
'post',
{
myobject: fbObjectId, // retrieved in an earlier FB.api call
access_token: accessToken, // retrieved in an earlier FB.getLoginStatus call
message: customTextFromUser, // prefilled by my app (FB doesn't approve of this)
image: ImageURL, // prefilled by my app (FB is OK with this I think)
'fb:explicitly_shared': true // requires that I take the user out of the normal flow of the app which is why I want to show a modal first
},
function(response) {
// handle the response
console.log(response);
if (response.id) {
alert("Success! The user story has been shared on Facebook!");
} else {
alert("Woops! Something went wrong sharing the user story on Facebook. Please try again.");
}
}
);
What I think I need to do is show a modal dialog box such as in the case of when FB.ui is invoked to give the user an opportunity to add a User Message and then post the user story along with the User Message (if any).
Will I need to create my own custom modal dialog box or can I use FB.ui in some way to achieve this?
Note: The above API call works fine in my tests. Granted, variables such as mynamespace, myobject, and myaction have been obscured in the above code sample.
My real problem is the user story is just not being approved by Facebook because I supposedly need to "take the user out of the normal flow of the app" in order to Explicitly Share the user story with an additional optional User Message. I guess I need a strategy to address this issue rather than a specific code sample answer.
Here is the latest feedback I got from Facebook:
Your action doesn’t follow section IV.2 of the Platform Policies:
https://developers.facebook.com/policy/.
Words in the user message field must be manually written by the user
and can’t be pre-filled by the app, even if the user can edit or
delete the words. Learn more about user messages:
https://developers.facebook.com/docs/submission-process/opengraph/guidelines/action-properties/#usermessages.
Posting explicitly shared content needs to be optional for users. A
sharing control needs to be in-line whenever a user shares something
and it can’t be in a separate settings area. The content should have a
user-generated component or the user needs to be taken out of the
natural flow of the app in order to decide to publish the story back
to Facebook. Your current action integration shouldn’t be labeled as
“explicitly shared.” Learn more about explicitly shared content:
https://developers.facebook.com/docs/submission-process/opengraph/guidelines/action-properties/#explicitlyshared.
If you use a test user created for your App, or use your developer account, you should be able to see the story published before it's approved.
The API call you're making also needs to be updated slightly. Instead of using User ID in the FB.api, just use /me/mynamespace:myaction. The access_token also doesn't need to be included, as it's automatically passed by the call providing the user is logged in.
Finally, is your object actually called myobject? The name must match the settings you entered for your story, e.g. 'article` or another valid type.
To help debug the issue, try a simple API call first (e.g. remove message and image) and see what happens. Then add the other parameters back one by one to see which one is causing the issue.
Edit
To get the action approved, you need to make sure the user is entering a custom message in one form or another - usually via text input on the page. If you are sharing pre-defined text the user hasn't entered, facebook won't approve it.
If you want to share a pre-written message, it might be better to share it in another way, like a caption in the story itself.
In the project of mine I made a component that creates a User for Joomla and Virtuemart via a form. Administrator requested that no group has to be assigned to the newly created user until administrator decides to. User has to be automatically activated too. Please don't ask me why, this what I have been asked to do :(
When Administrator assigns a userGroup to the user, an email should be sent to the user to notify the user of this action so user can login.
I couldnt find any solution for it, I cant find a trigger that notify me when user assigns to a UserGroup either so I make a plugin for it.
Joomla is 2.5.8
Thank you in advance.
You can use JUtility/sendMail to send emails.
Now where to triggre email using sendMail?
Go to /libraries/joomla/user/helper.php file.
Inside, there is a method public static function addUserToGroup($userId, $groupId).
Most probably this is the method which is called. You may extend/override this method to add a custom custom code to trigger an email if assigning a userid to groupid is successful.
You may put a check for boolean return value on this part.
// Store the user object.
$user->save();
So if it is successful, the email will be triggered!
Hope it helps! Any better ideas are welcome.