I would like to provide a link when clicked it will send an email to an admin to inform them to delete a record. I have searched for several hours, included here but could not find any examples.
Here is the current code I would like to modify:
link_to "Delete your User Account?", #user, method: :delete, confirm: "You sure? This will permanently delete your account. If you want to access our site in the future you will need to create a new account again. Are you sure you want to delete your account?" %>
I would like to substitute "method: :delete" with an ActionMailer method. I looked in the Ruby documentation at api.rubyonrails.org and other places for examples but could not find anything.
Is this something I can do without installing a gem?
Why is it so hard to find documentation with examples? Sigh.....
The "method: delete" is the HTTP methods passed in the headers when you call the url which is then used by the routes to find the correct controller and action.
You will want to place your method calls to the mailer in your controller where User#destroy action is.
it would be something like this.
def destroy
#user = User.find(params[:user])
if #user.desotry
# Tell the UserMailer to send a email after destroy
UserMailer.delete_account_email(#user).deliver
redirect_to(#user, :notice => 'Account was successfully closed.')
end
end
Related
Is there a way to make a Jire email handler ignore the From field in an email and go for a custom tag instead? I know I could work with the API instead but that's in the pipe. this is a temporary solution that will be used until a more robust system is built.
To clarify what we have today:
Email is sent to inbox, (hr#company.com)
Jira picks is up and creates an issue.
Jira looks at the From field and creates a uses if none exist.
What we're trying to achieve:
Form is filled out, and an area is chosen (hr, facilities etc.).
Form is posted to an API that creates an email (basically a no-reply adress over SMTP) and sends it to the appropriate inbox (for example hr#company.com).
Email lands in the inbox and Jira looks in it and creates an issue in project or label 'HR'.
Jira now looks in the email and finds custom tags named [user] and [user-email] (or something) and creates a user from the tag.
Example email
From: no-reply#company.com
To: hr#company.com
Subject: Some problem
Body: Explanation of problem
Have a good day!
/Mike
[user:"Michael Smith"]
[userEmail:"michael.smith#company.com"]
If we were to implement this system now, we would loose the possibility to create new users because all emails would come from the same "no-reply" adress.
I have searched in the Atlassian forums and such, but with no luck. Have not found anything in the official documentation, but I fear that I might be looking in the wrong place.
I hope that I'm being clear, and that someone has any idea if it is possible.
Thank you!
You need to write your own plugin and create your own Mailhandler.
For example you can use a regex which looks for the tag
[userEmail:"michael.smith#company.com"] and retrieve the emailadress from the string. Do the same for the [user]-tag, if the user doesn't exist.
Here is a tutorial that shows how to create and setup custom Message Handlers:
https://developer.atlassian.com/jiradev/jira-platform/guides/email/tutorial-custom-message-mail-handler-for-jira#Tutorial-Custommessage(mail)handlerforJIRA-Step7:Implementarealmessagehandlerback-end
The rest should be easy from here.
I am using this method to login with google plus, It's working properly, I need email of user in callback but this method in return did not give email address. what should I do for email, is their any other method which return email or we can get user email using access token?
You need to add an additional scope to the request. Email-providing scopes have recently changed, with older ones being deprecated. The full list is at https://developers.google.com/+/api/oauth#email-scopes, but you can probably safely just use the email scope in addition to the https://www.googleapis.com/auth/plus.login scope. Scopes are specified by listing them with a space between each one, so your button configuration might look something like this:
<span id="signinButton">
<span
class="g-signin"
data-callback="signinCallback"
data-clientid="CLIENT_ID"
data-cookiepolicy="single_host_origin"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-scope="https://www.googleapis.com/auth/plus.login email">
</span>
</span>
You would use the people.get API to access the full profile of the user, which would include the emails array. Each element of the array contains the type of the address (home, work, etc) and the address itself. The email scope just lists the address directly associated with the account, while other scopes provide other publicly available addresses, so they may not provide further information.
Note that the older userinfo.* scopes are deprecated and may stop working in September 2014. See https://developers.google.com/+/api/auth-migration#timetable for details.
Update: To be clear - the sign-in button does not give you the email itself. It requests permission to get the email address and user profile information. What it gives you is an access token that you can use for further requests.
As both #DalmTo and I have pointed out, in order to actually get the information, you need to call the API endpoint of people.get. Go to this page and go to the Examples section and select JavaScript from the pull down for an example. You will also need to load the javascript client library: see https://developers.google.com/api-client-library/javascript/samples/samples for some examples, but in particular you will need a line like
<script src="https://apis.google.com/js/client.js?onload=onLoad"></script>
which loads the client library (and calls the onLoad() function when it has been loaded) and then something like
<script>
function onLoad(){
gapi.client.load('plus', 'v1', onClientLoad);
}
</script>
The onClientLoad() callback will be called when the client is loaded, and should set a marker to indicate things are set to make the call. Then, as part of the signinCallback() function, you would make sure this marker is set (indicating the client library is ready) and use the gapi.client.plus.people.get() method to make the request. Possibly something like this as part of the signed in block:
gapi.client.plus.people.get({
'userId': 'me'
}).execute(function(response){
console.log(response);
});
This does a call to people.get, requesting the profile of a particular user. The special userid of "me" indicates it should be for the user that is signed in. Calling execute() with a callback function executes the request, returning a response object. In this example, we're just printing it, but it will be a JSON object containing the user's profile.
You need to add another scope https://www.googleapis.com/auth/userinfo.email it should let you request the email address then using plus.people.get
<span id="signinButton">
<span
class="g-signin"
data-callback="signinCallback"
data-clientid="CLIENT_ID"
data-cookiepolicy="single_host_origin"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-scope="https://www.googleapis.com/auth/plus.login,https://www.googleapis.com/auth/userinfo.email">
</span>
</span>
you can test the API here: plus.people.get
Note: a user can have more then one email you probably want the one with type account
I'm trying to redirect the user to another page (default/news) after the login(on default/index) but no matter how much i tried i couldn't get it done. I'm using the login available in the navbar.
I've added this line to db.py
auth.settings.login_next=URL(r=request, c='default', f='news')
Everything in the default controller is the same it includes
def news():
message = "Welcome to News!"
return locals()
I've also tried with this
auth.settings.login_next=URL('news')
Which doesn't work either. Please Help.
Edit:
After searching for days i've found the answer here This is how you do it.
#In layout.html change
<ul id="navbar" class="nav pull-right">{{='auth' in globals() and auth.navbar(mode="dropdown") or ''}}</ul>
# to
<ul id="navbar" class="nav pull-right">{{='auth' in globals() and auth.navbar(mode="dropdown",referrer_actions=None) or ''}}</ul>
And again a change in db.py
#In db.py add these lines:
auth.settings.login_next = URL('news')
That worked for me.
The auth.settings.login_next URL is only a default in case there is no referrer already in the login URL (the referrer is in the "_next" query string variable). The navbar automatically includes a referrer in the auth action links (set to the URL of the current page) -- to override that, you can explicitly specify thereferrer_actions argument and exclude actions for which the referrer should not be set:
{{=auth.navbar(..., referrer_actions=['register', ...])}}
It's now April 2016, and while the original question is still highly relevant, it appears that web2py has changed and the modifications suggested above to layout.html are no longer relevant. There is no reference to "auth.navbar" in the standard layout.html.
The good news is, that all one needs to do is include the python code described above in the default.py controller and it works. Note, I put it in the 'user' function, I'm not sure if that is the best place to put it as most comments just say to put it in 'the controller', without specifying a function.
def user():
auth.settings.login_next = URL('default','dashboard')
return dict(form=auth())
I was able to redirect to a user's home page after login/signup by putting the following code in my product info page.
This way, when they get redirected back to the welcome-product-info page, I check to see if they came from login or signup and direct them to where they should go.
I'd love to find way to use auth.settings.login_next
#
def info():
# If just signed up or just logged in, go to the user's home page and not
# back to this product landing page that referred them
if auth.is_logged_in():
if '/default/user/login?_next=/fnd/home/info' in request.env.http_referer:
redirect( URL( 'user', 'show_campaigns') )
if '/default/user/register?_next=/fnd/home/info' in request.env.http_referer:
redirect( URL( 'user', 'show_campaigns') )
return dict()
I am writing a Redmine plugin. I already have the model, view and controller in place.
Whenever someone creates, updates or deletes my model I want to send an email to people in a certain group. (Similar to emails sent out by Redmine when someone creates or updates an Issue) Could someone please let me know what would be the best way to go about it?
Thanks!
I know it's been 2 years since you asked but I had the same issue and I figured out how to send an email with my plugin.
What you have to do for a plugin named my_plugin is :
1. Create a Model which inherits from Mailer.
So if I want a mailer named MyPluginMailer :
I create redmine_folder/plugins/my_plugin/app/models/my_plugin_mailer.rb
I create the MyPluginMailer class which inherits from the redmine Mailer
Like that:
class MyPluginMailer < Mailer
end
2. Create a method to call on the mailer.
Say I am writing a news plugin for redmine.
I want to send an email which summarizes the article I submitted so that users do not have to poll the plugin each time they want to know if there is something new.
I create a method in my mailer class :
class MyPluginMailer < Mailer
def on_new_article(user_to_warn, article)
mail to: user_to_warn.email, subject: "New article: #{article.title}"
#article = article #So that #article will be available in the views.
end
end
You can call this method in your Article class in an after_create callback for example.
3. Create some views for the method.
I have to create 2 differents files :
my_method.html.erb
my_method.text.erb
or else redmine is going to crash with a "template not found" exception.
So in my redmine_folder/plugins/my_plugin/app/views/my_plugin_mailer/ I create
on_new_article.html.erb
on_new_article.text.erb
In my on_new_article.html.erb I write something like :
<h1><%= #article.title %></h1>
<p><%= #article.summary %></p>
I'm using devise/omniauth to do facebook authentication and works great. However, I would like to add a flow where an existing (non-facebook) user has ability to connect his account with facebook. This would require different facebook permissions. so i can't seem to find two things
how to use devise/omniauth to request facebook connect without logging out current user
request different extended permissions from user (different from those specified in the devise configuration file)
any ideas? thanks
Answer to 1 is pretty easy: just add a if path into the omniauth_callbacks_controller::process_callback method like this
# If a user is signed in then he is trying to link a new account
if user_signed_in?
if authentication.persisted? # This was a linking operation so send back the user to the account edit page
flash[:success] = I18n.t "controllers.omniauth_callbacks.process_callback.success.link_account",
:provider => registration_hash[:provider].capitalize,
:account => registration_hash[:email]
else
flash[:error] = I18n.t "controllers.omniauth_callbacks.process_callback.error.link_account",
:provider => registration_hash[:provider].capitalize,
:account => registration_hash[:email],
:errors =>authentication.errors
end
redirect_to edit_user_account_path(current_user)
This is what I do in my application and it works fine.
Regarding question 2 I do not know how to support 2 different facebook authentication configurations however I have hard time seeing how that is useful to users since they need a consistent experience across both path: "sign in using facebook" and "link your account to facebook".
(If you still want to pursue this path one idea I would explore is to create a new facebook application with its independent keys and configuration...)
Hope this help.
One simple way to implement multi-tier permissions is to use Facebook Javascript SDK(in addition to omniauth, if you want). You can simply specify different "scope" parameter, which specifies permissions required, at each call you want. What I'm doing is making omniauth provide a basic set of permissions, then, after the user has connected through omniauth(and thus stored their data in our DB), if further permissions are needed, we show them JS-based buttons which provide expanded sets of permissions. If you want to check what particular permissions a user has granted to you, you can simply use me/permissions API call.