Overriding default invalid email message in Grails - grails

How can I override default message when email address isn't valid.
I have following constraints:
constraints = {
...
email blank:false, email:true
}
I was trying to display message in the messages.properties with different combinations:
domainName.email.error
domainName.email.invalid
domainName.email.email
I'm able to display message when email is blank. Obviously I was trying to restart grails after modification, but it still doesn't works.
Thanks in advance for any help.

The correct message code to use for each constraint type can be found on the user guide page for the relevant constraint (choose the constraint you need from the right hand column). In the case of email it is
className.propertyName.email.invalid
so in your case
my.pkg.DomainClassName.email.email.invalid
(the first email being the property name and the second email being part of the email.invalid code).

Related

Django email verification - customize email html & 404 not found accounts/profile/

I have two issues. Email verification works well, but I want to customize the email sent to users. Here is the content of the email:
Hello from Localhost!
You're receiving this e-mail because user test has given yours as an
e-mail address to connect their account.
To confirm this is correct, go to
http://127.0.0.1:8000/rest-auth/registration/account-confirm-email/MTE:1h4DCn:JtkrZ1wkENQIdG8ysIVu7Qx_R44/
Thank you from Localhost! https://localhost:8000/
How can I create an html file and fill in the content that I want to be sent in the email? And how about the email subject?
The second issue, is that when I click on the link, the user gets verrified, but then I get a 404 error on /accounts/profile.
Here is my code:
from allauth.account.views import confirm_email
urlpatterns = [
path('accounts/', include('allauth.urls')),
path('rest-auth/', include('rest_auth.urls')),
url(r'^rest-auth/registration/account-confirm-email/(?P<key>[-:\w]+)/$', confirm_email),
path('rest-auth/registration/', include('rest_auth.registration.urls')),
]
Do I have to add a url for accounts/profile/ and create an html template showing that the email verification was successful? Also, is there a way to change to url to i.e accounts/verification-success/?
Custom e-mail
You can find the default e-mail templates used here: https://github.com/pennersr/django-allauth/tree/master/allauth/templates/account/email
Subject: email_confirmation_subject.txt
Text e-mail: email_confirmation_message.txt
You can override them in your Django app like any other template.
To activate HTML, you just have to add your own file with the name email_confirmation_message.html.
You can also have different messages when you signup or just confirm an e-mail address.
You can have a look into the code to understand how it works.
accounts/profile/
When you end up here you have successfully logged in. However, you will need to implement a view for this URL yourself, as whatever is to be displayed here is project specific. You can also decide to redirect elsewhere:
https://docs.djangoproject.com/en/dev/ref/settings/#login-redirect-url
From https://django-allauth.readthedocs.io/en/latest/faq.html#when-i-attempt-to-login-i-run-into-a-404-on-accounts-profile
Since you have to implement the profile yourself, you can use accounts/verification-success/, too.

mIRC parsing for a name

So I've been getting a bothersome someone who keeps using my nickname. What I want to be able to do is perform the following command every time someone with exactly my nickname (let's say UserName) joins the channel I currently reside in:
/msg NickServ ghost UserName n0ideaHwatPassIs?
n0ideaHwatPassIs? is a sample password for our sample registered user of UserName
This sort of script would have to be able to check (in more or less real-time) if a separate user changed his/her nick to said UserName as well. If someone would be so kind as to help me with my dilemma by either pointing me to the proper documentation or working out such a script (no idea if this is as cut-and-dry as I imagined it would be at first) for me?
you can use a on notify event
but first, you have to put that nickname on notify list
type
/notify nickname
then use this script, press alt+r click on file, then new and put this script in there
on *:notify:{
if ($nick != $me) && ($nick == Nickyouwanthere) {
msg NickServ ghost UserName n0ideaHwatPassIs
}
every time someone with exactly my nickname (let's say UserName) joins the channel I currently reside in
This can't happen on IRC. (Except in exceptional circumstances like netsplits, but is immediately resolved then (by dropping one or both parties))

Modifying error messages for Command Objects embedded in controller

I am trying to modify the messages.properties file for form input validated by a Command Object that is in specified in the controller. The output I get from the standard error message (that I modified slightly to assure I was hitting that specific one) is:
email cannot be empty test class com.dashboard.RegisterController$DashboardUserRegistrationCommand
but no variant of com.dashboard.RegisterController$DashboardUserRegistrationCommand.null.message
works
I am wondering what the correct specification should be.
Try to put DashboardUserRegistrationCommand outside (below) of RegisterController but still in the same file. Then com.dashboard.DashboardUserRegistrationCommand.. should work.
i.e. com.dashboard.DashboardUserRegistrationCommand.message.nullable
The typical layout of error messages is:
${packageName}.${className}.${propertyName}.${errorCode}
So for your example it would be:
com.dashboard.DashboardUserRegistrationCommand.message.nullable
In the Grails Reference on the right hand side there is a header titled 'Constraints'. On each page of the specific constraints listed under that header the ${errorCode} value is listed at the bottom of the page.
And sometimes you have to restart a run-app to get new messages to populate in a Grails project.
Just to help others in the future, I had the same issues and my problem was the way I was defining my key, I use now:
For default messages:
default.null.message=Write a value for {0}
For commmand error messages:
my.package.UserCommand.name.nullable=Please tell us your name
It is strange that sometimes you use nullable and sometimes you use null. The best thing is going to the Grails Constraints directly and check how is it done for example:
http://grails.org/doc/latest/ref/Constraints/nullable.html

Typemismatch with I18N Label instead of Attribute Name

My message.properties contains this by default:
typeMismatch.java.lang.Double=Property {0} must be a valid number
Placeholder {0} is replaced by the Attribute Name. I want to use the Label that is used for the frontend like this:
typeMismatch.java.lang.Double=Property {wonderful label here} must be a valid number.
My first Attempt:
typeMismatch.java.lang.Double=Property ${message(code:'0')} must be a valid number.
is not working cause there is no '0' message. Documentation is not clear at that point.
Anyone got an idea for this one?
Edit:
Well i can write an error message for every Attribute like this:
typeMismatch.Book.booknumber = Property Booknumber must be a valid number.
But this seems like a lot of extra work...
So I made an little mistake.. it is damm easy now...I'll answer it here. Maybe someone will run into this:
My Mistake was:
typeMismatch.java.lang.Double=Property {0} must be a valid number
{0} was replaced by the Attributes Name.
The Reason behind that was that Grails API rendererror is looking for correct Classnames and Properties.
For example:
My Class is named Book and Property is number.
In my message properties:
book.number = Booknumber
For i18n everything worked fine, but when the error message has to occur it shows the following:
"Property number must be a valid number."
Correct Version in message properties:
Book.number = Booknumber
Works for me now. :-)
Awesome! Thanks so much for your post!
When it didn't work for me at first, it took me some time to realize that I needed to use the fully qualified class name in front of the property name. So the syntax is:
package.ClassName.propertyName=Label
Very useful! Thanks again!
Al
Spring's Data binding error validators ("{0}" must be a valid number) want fullClassName.fieldName
Short class name and/or .label are not recognized, see org.springframework.validation.DefaultBindingErrorProcessor#getArgumentsForBindError
Grails validators ("{0} must be a valid email address") want FQClassName.fieldName.label or classPropertyName.fieldName.label
Adding .label is a must, as evident from org.codehaus.groovy.grails.validation.AbstractConstraint#rejectValueWithDefaultMessage
Hence you need both FQN/shortClassName.attributeName.label and FQN.attributeName to get the same translatable human-friendly name in both validations.
http://jira.grails.org/browse/GRAILS-8369
One other hint, in case it helps the next person, if you are getting an unfriendly error message like "Property producer.employeeCount must be a valid number" try adding a property called simply producer.employeeCount to your messages.properties file, as such:
producer.employeeCount=Number of Employees
At least in Grails 2.0.0, this will result in a friendlier message: "Property Number of Employees must be a valid number."
Using the fully qualified class name (e.g. com.example.domain.Client.employeeCount), with or without ".label" at the end did not work for me.
Hope this helps someone.

Salesforce Create Buttons and Links option - Custom URL to launch email template

I have an email template that I would like to launch from within the case using a Link/Button. I see the option under setup->customize->cases->button and links I even see where I need to place the URL. What I don't see is nay documentation on how to build the URL to launch an email template. Any help you be great
I don't know if this is documented anywhere by salesforce, but I found from some guess work:
/_ui/core/email/author/EmailAuthor?p3_lkid={!Case.Id}&p2_lkid={!Case.ContactId}&template_id=00X40000000weWn
Just use that as the url content of a custom button or link. This one is for cases, as you are trying to do, but I think this should work for other types of objects as well.
The parameters are p3_lkid, which is the case id, p2_lkid which is the id of the contact you are emailing, and template_id which is hardcoded to the desired email template. (You can find this id by looking in the url of the Setup page for the template)
This was really helpful. I did, however, figure out another way to do it. Click on the "Send an Email" button you currently have. Copy the URL and add &template_id=YOUR TEMPLATE ID.
There is one other ID number that will show up in the original URL. Change that to be the dynamic field you want it to be.
For example:
Copy url from "Send Email": https://na3.salesforce.com/_ui/core/email/author/EmailAuthor?p3_lkid=70150000000Axj1&retURL=%2F70150000000Axj1
Add &template_id=YOUR TEMPLATE ID so it looks like this:
/_ui/core/email/author/EmailAuthor?p3_lkid=70150000000Axj1&retURL=%2F70150000000Axj1&template_id=YOUR TEMPLATE ID
Remove the other id (it's the object you used to send the email - so in this case, I was wanting to be able to send an email directly from a Campaign) and replace with the dynamic field:
/_ui/core/email/author/EmailAuthor?p3_lkid={!Campaign.Id}&retURL=%2F70150000000Axih&template_id=YOUR TEMPLATE ID
And voila! It should work!
Abeyer's answer is good. However, if the template contains solution attachments "{!Case.Solution_Attachments}" the attachments will not get included unless you add the new_template=1 parameter to the URL making it:
/_ui/core/email/author/EmailAuthor?p3_lkid={!Case.Id}&p2_lkid={!Case.ContactId}&template_id=00X40000000weWn&new_template=1

Resources