I wanted to send a notification to the user (or invoke any function in that case) if the attribute of the object is changed (For eg, an attribute ‘is_checked’ is changed to True) from the admin panel. Upon digging through the Django source code, I found the log entry class that is used in the admin panel.
def check_state_change():
logs = models.LogEntry.objects.all()
for log in logs:
if log.action_flag == 2:
if log.change_message == “[‘is_checked’]”:
function(*object whose attribute was changed*)
for now I am checking all the logs
The above function does the job but I am unsure about the ways to invoke this function. Do I call it every 5mins or what are the better ways?
Related
I'm trying to implement the next logic in AWS Cognito:
AWS lambda catch CustomMessage_ForgotPassword event,
Lambda function returns HTML template, which contains Reset code and what I'm trying to do is to adding a button with the link, which should redirect user to the Cognito form, where he enter Code + new password.
I've create link https://${ENVIRONMENT}/confirmForgotPassword?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_APP}&scope=openid%20profile%20email&response_type=token&user_name=${userName}&confirmation_code={####}.
When I click on the link inside email I navigate to the page, which shows me an error:
I would like to navigate:
The question: Is it possible to send a code with the constructed link to the form by email?
Lambda function returns HTML template, which contains Reset code and what I'm trying to do is to adding a button with the link, which should redirect user to the Cognito form, where he enter Code + new password.
I don't think this is possible. The person should already be on that page, having just clicked the "reset password" link, which triggered your Lambda function to run, so they shouldn't need another link to the same page. Or they just logged in and landed on the reset page, because you flagged their account as needing to reset the password. In either case, they are already on the page that is waiting for them to read the code your Lambda function generated, and type it into the input field. That page is not designed to be refreshed, or loaded directly, as it could pose a security risk if bots could spam that page with different codes.
I have written an automation script for a website, when i am passing credentials and clicking on submit, the page gets refreshed with no content in the textbox, it is not signing in.On doing the same process manually it works.
user = driver.find_element_by_xpath('//*[#id="txtUserID"]')
user.send_keys(user_id)
password_1 = driver.find_element_by_xpath('//*[#id="txtPassword"]')
password_1.send_keys(password)
submit_button = driver.find_element_by_xpath('//*[#id="btnLogin"]')
submit_button.click()
By your statement, there could be a possibility that you click the submit button even before the Username and password field is updated with the keys. Try adding delay in between to test if your User id and password are updated and visible in the fields.
Alternatively there could be a chance that you are sending the User id and password to a wrong element.
for sure there is need to trigger onChange event on element, because some elements has hook on that, and if no event triggered, it thinks there is no data inside :)
driver.executeScript("arguments[0].dispatchEvent(new Event('change'))", driver.find_element_by_xpath('//*[#id="txtUserID"]'));
or made custom sendkeys() method thenwith this magic inside, to not copypaste :)
I am currently running a local Sitecore at version 7.2 rev 140526 and Web Forms for Marketers at 2.4 rev 150619. I am currently experiencing an SMTP failure to authenticate error when using the WFFM SendEmailMessage default save action.
After some investigation, I discovered that this is because WFFM's internal EmailAttributes class that stores the SMTP config (that comes from either the web.config or the Parameters field on the SaveAction itself, as per their documentation) was using an old SMTP password that was changed over a year ago.
That is to say, the values retrieved by the following two lines of code were different despite the fact that the mail server password in the webconfig and Parameters fields specify the same value:
var configPassword = Sitecore.Configuration.Settings.GetSetting("MailServerPassword");
// EmailAttributes.Password
var basePassword = Password;
This old password that is returned when accessing the EmailAttributes.Password field is not present in the web.config in either the solution or the Sitecore/Website directory nor is it present in my local showconfig. Futhermore, the old password is not present in the Parameters field of the default WFFM SendEmailMessage save action and the following Sitecore query executed against Core, Master and Web database yields no results:
fast://*[#Parameters = '%fooBar%']
It is also worth noting that if the value contained in the configPassword variable (which is the correct password) is used to overwrite the value contained in the EmailAttribute's Password field (e.g. Password = configPassword) mail is sent successfully and there is no authentication error with the SMTP server.
We have a custom SendEmail save action that inherits from Sitecore.Form.Submit.SendMessage, overrides the Execute method, manipulates the fields collection and calls base.Execute() and emails are sent successfully.
Also, in WFFM v 2.3.0 rev 130118 there is no SMTP failure to authenticate exception thrown when using the default SendEmailMessage save action provided by WFFM when using the same SMTP configuration in the web.config file and config injected into the Parameters field of the SendEmailMessage save action.
I am at a loss for how/why the EmailAttributes.Password field would be getting a value that is not present in config, not coming from the Paremeters field on the SaveAction in sitecore, and isn't configured manually in the SMTP Email IIS module.
Any insight would be much appreciated!
The issue is most likely due to the way that the WFFM parameters are stored. Unfortunately the save action is not stored as a reference to the original when you add an action to a form. What actually happens is the parameters are copied from the parameters field of the Save Action to the Save Actions field on the form when it is added. Since it is a copy and not a reference, changing the parameters on the original save action does not change any existing forms using that save action.
You can verify this by going to the the form in Content Editor, go to View ribbon and ensure Standard Fields and Raw Values are both checked. Then check the Save Actions field under the Submit section. You should find the password within the XML in the <parameters> node.
There are 2 options to fix this:
Delete the send email save action from your form and add it in again
Edit the XML from the Save Actions field to remove the Password
I'm trying to create a kind of quick response form where a user does not need to login but is identified with his uuid (in the url). Moreover i need to restrict his permissions for this session so that he only could to a few things.
User gets url with UUID and ID of event (Where he can response)
User clicks on link and response page opens
User is identified via uuid
With the id of the event the event response form is generated
User can chose options and submit the form
Normally there are multiple other options (e.g. in the menue) available but these should only be accessible if user identifies with his username and password.
Of course i could write a special view but is there a more elegant way where i could reuse my existing view for the response?
First you'll want to use the UUID to trigger the login.
How you approach this will depend on whether you mind using a specific login url/view or you want people to arrive directly at the intended url/view (just with the UUID parameter). If you use a specific view you'll check the UUID, (presumably mark it as used/expired), then login the user. Alternatively for the UUID to checked and have users login via any url/view, you'll want a to use a custom middleware that's placed ahead of AuthenticationMiddleware in your middleware settings. In each case, once you have the logged in the user, you'll want to store in session some sort of flag to indicate they've auth'd via a temporary login UUID.
Now that you've authenticated and logged in the user via the UUID, it's time to serve them the view. At this point in your View you'll check for presence of the flag in the user session to determine their permissions.
You could go further and create another middleware class to encapsulate the session lookups and add a property, say "is_auth_temporary", to the request.User object that is a sibling to the is_anonymous and is_authenticated property.
In this Django code I inherited there is a check for request.user.is_authenticated().
How do I set this authenticated attribute for a user, in particular when I am doing a registration through AJAX JSON?
To log a user in, you should django.contrib.auth.login - see the docs here: https://docs.djangoproject.com/en/1.5/topics/auth/default/#auth-web-requests
Note, though, that you should authenticate the user (i.e. check their credentials) before you do so, with django.contrib.auth.authenticate - same docs as above.
This is regardless of whether you're using AJAX or not - this code has to be in a view somewhere that gets called in order for the user to get logged in. Whether that view is called via AJAX or not is irrelevant.
The only user this will return false for is AnonymousUser; all other users have it return true via their superclass. Therefore all you need to do is authenticate the user normally.