Hi all, I need a help. I have got a user registration form, where the user signs up and then an activation link is sent to the user email id for activating his/her account. Now I need to send an another email to the user, only after he logs in for the first time in my site, then the second email should be sent. Can anybody give me some suggestion on how to do it ?? NB: When the user clicks on the activation link, he is not directed to user home page, only the home page of my website is displayed. Thanks Saurav -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
andrew.ohnstad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Apr-25 09:50 UTC
Re: ActionMailer
In your controller where you check the activation link, mark the user as activated, call a second ActionMailer, and then redirect. In the following example the user gets an email with a link that points to www.yoursite.com/process_activation/<ACTIVATIONCODE> There is a "Mailman" model which is your ActionMailer. def process_activation if user = User.find_by_activation_code(params[:id]) user.active = true #or however you mark a user as fully active user.save Mailman.deliver_after_activation(user) redirect_to... and return #this is where a validated user should go else flash[:error] = "Invalid Activation Code" redirect_to... #or do whatever you want here when someone has an invalid code end end This isn''t 1000% secure, it doesn''t actually match the user with the code, etc. But it''s good enough for me. If it''s not good enough for you then it''s easy enough to adapt. Of course, you need a standard ActiveMailer model and view. ''user'' will be passed to it. On Apr 25, 6:25 am, Saurav Chakraborty <rails-mailing-l...@andreas- s.net> wrote:> Hi all, > > I need a help. I have got a user registration form, where the user signs > up and then an activation link is sent to the user email id for > activating his/her account. Now I need to send an another email to the > user, only after he logs in for the first time in my site, then the > second email should be sent. Can anybody give me some suggestion on how > to do it ?? > > NB: When the user clicks on the activation link, he is not directed to > user home page, only the home page of my website is displayed. > > Thanks > Saurav > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Andrew, Thanks for the interest. But this is not my problem. Rite now Im able to send the email once the user clicks on the activation mail. But what I really want is that the welcome email should go to the user only after he first logs into my website. Im using restul_authentication plugin my user_observer.rb file is class UserObserver < ActiveRecord::Observer def after_create(user) UserMailer.deliver_signup_notification(user) end def after_save(user) UserMailer.deliver_activation(user) if user.pending? end end So when a user signs up initially the mail having the activation link is being sent. When the user clicks on the activation link, another email is sent to the user. But I want this second email to sent only after he logs in the site for the first time. I m stuck here. On Apr 25, 2:50 pm, "andrew.ohns...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <andrew.ohns...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In your controller where you check the activation link, mark the user > as activated, call a second ActionMailer, and then redirect. > > In the following example the user gets an email with a link that > points towww.yoursite.com/process_activation/<ACTIVATIONCODE> > There is a "Mailman" model which is your ActionMailer. > > def process_activation > if user = User.find_by_activation_code(params[:id]) > user.active = true #or however you mark a user as fully active > user.save > Mailman.deliver_after_activation(user) > redirect_to... and return #this is where a validated user should > go > else > flash[:error] = "Invalid Activation Code" > redirect_to... #or do whatever you want here when someone has an > invalid code > end > end > > This isn''t 1000% secure, it doesn''t actually match the user with the > code, etc. But it''s good enough for me. If it''s not good enough for > you then it''s easy enough to adapt. > > Of course, you need a standard ActiveMailer model and view. ''user'' > will be passed to it. > > On Apr 25, 6:25 am, Saurav Chakraborty <rails-mailing-l...@andreas- > > s.net> wrote: > > Hi all, > > > I need a help. I have got a user registration form, where the user signs > > up and then an activation link is sent to the user email id for > > activating his/her account. Now I need to send an another email to the > > user, only after he logs in for the first time in my site, then the > > second email should be sent. Can anybody give me some suggestion on how > > to do it ?? > > > NB: When the user clicks on the activation link, he is not directed to > > user home page, only the home page of my website is displayed. > > > Thanks > > Saurav > > -- > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Andrew, Thanks for the interest.Actually this is not the problem Im facing. Rite now Im using restful authentication plugin, and with this Im able to send the email after user has clicked on the activation link. But what I really want is that no email should go to the user after he activates himself.What I really want is that only after the activation when the user first logs into my site, then only an email should be sent to him. I think some sort of tracker is needed for the user login. But Im not really understanding on how to do it Andrew Ohnstad wrote:> In your controller where you check the activation link, mark the user > as activated, call a second ActionMailer, and then redirect. > > In the following example the user gets an email with a link that > points to www.yoursite.com/process_activation/<ACTIVATIONCODE> > There is a "Mailman" model which is your ActionMailer. > > def process_activation > if user = User.find_by_activation_code(params[:id]) > user.active = true #or however you mark a user as fully active > user.save > Mailman.deliver_after_activation(user) > redirect_to... and return #this is where a validated user should > go > else > flash[:error] = "Invalid Activation Code" > redirect_to... #or do whatever you want here when someone has an > invalid code > end > end > > This isn''t 1000% secure, it doesn''t actually match the user with the > code, etc. But it''s good enough for me. If it''s not good enough for > you then it''s easy enough to adapt. > > Of course, you need a standard ActiveMailer model and view. ''user'' > will be passed to it. > > On Apr 25, 6:25�am, Saurav Chakraborty <rails-mailing-l...@andreas--- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I was thinking that you could have an initial_login boolean field in your users table that could initially be set to false. Each time a user logs in, you could call a method that sees if the user has logged in before (i.e., is initial_login still false?), and if not, sends the user an email and sets initial_login to true. -Kyle On Apr 25, 5:28 am, prionko <prio...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Andrew, > Thanks for the interest. But this is not my problem. Rite now Im able > to send the email once the user clicks on the activation mail. But > what > I really want is that the welcome email should go to the user only > after he first logs into my website. > Im using restul_authentication plugin > > my user_observer.rb file is > class UserObserver < ActiveRecord::Observer > def after_create(user) > UserMailer.deliver_signup_notification(user) > end > > def after_save(user) > > UserMailer.deliver_activation(user) if user.pending? > > end > end > > So when a user signs up initially the mail having the activation link > is being sent. When the user clicks on the activation link, another > email is sent to the user. But I want this second email to sent only > after he logs in the site for the first time. I m stuck here. > > On Apr 25, 2:50 pm, "andrew.ohns...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" > > <andrew.ohns...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > In your controller where you check the activation link, mark the user > > as activated, call a second ActionMailer, and then redirect. > > > In the following example the user gets an email with a link that > > points towww.yoursite.com/process_activation/<ACTIVATIONCODE> > > There is a "Mailman" model which is your ActionMailer. > > > def process_activation > > if user = User.find_by_activation_code(params[:id]) > > user.active = true #or however you mark a user as fully active > > user.save > > Mailman.deliver_after_activation(user) > > redirect_to... and return #this is where a validated user should > > go > > else > > flash[:error] = "Invalid Activation Code" > > redirect_to... #or do whatever you want here when someone has an > > invalid code > > end > > end > > > This isn''t 1000% secure, it doesn''t actually match the user with the > > code, etc. But it''s good enough for me. If it''s not good enough for > > you then it''s easy enough to adapt. > > > Of course, you need a standard ActiveMailer model and view. ''user'' > > will be passed to it. > > > On Apr 25, 6:25 am, Saurav Chakraborty <rails-mailing-l...@andreas- > > > s.net> wrote: > > > Hi all, > > > > I need a help. I have got a user registration form, where the user signs > > > up and then an activation link is sent to the user email id for > > > activating his/her account. Now I need to send an another email to the > > > user, only after he logs in for the first time in my site, then the > > > second email should be sent. Can anybody give me some suggestion on how > > > to do it ?? > > > > NB: When the user clicks on the activation link, he is not directed to > > > user home page, only the home page of my website is displayed. > > > > Thanks > > > Saurav > > > -- > > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You could also use a ''last_logged_in_at'' field that''s null by default. The email gets fired in response to the first login (field null=>value) and you also get a field that helps you understand how much your users are using the system (and the chance to send "You''ve been away for a while..." emails). On Apr 25, 2:49 pm, Kyle <kyle.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I was thinking that you could have an initial_login boolean field in > your users table that could initially be set to false. Each time a > user logs in, you could call a method that sees if the user has logged > in before (i.e., is initial_login still false?), and if not, sends the > user an email and sets initial_login to true. > > -Kyle > > On Apr 25, 5:28 am, prionko <prio...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi Andrew, > > Thanks for the interest. But this is not my problem. Rite now Im able > > to send the email once the user clicks on the activation mail. But > > what > > I really want is that the welcome email should go to the user only > > after he first logs into my website. > > Im using restul_authentication plugin > > > my user_observer.rb file is > > class UserObserver < ActiveRecord::Observer > > def after_create(user) > > UserMailer.deliver_signup_notification(user) > > end > > > def after_save(user) > > > UserMailer.deliver_activation(user) if user.pending? > > > end > > end > > > So when a user signs up initially the mail having the activation link > > is being sent. When the user clicks on the activation link, another > > email is sent to the user. But I want this second email to sent only > > after he logs in the site for the first time. I m stuck here. > > > On Apr 25, 2:50 pm, "andrew.ohns...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" > > > <andrew.ohns...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > In your controller where you check the activation link, mark the user > > > as activated, call a second ActionMailer, and then redirect. > > > > In the following example the user gets an email with a link that > > > points towww.yoursite.com/process_activation/<ACTIVATIONCODE> > > > There is a "Mailman" model which is your ActionMailer. > > > > def process_activation > > > if user = User.find_by_activation_code(params[:id]) > > > user.active = true #or however you mark a user as fully active > > > user.save > > > Mailman.deliver_after_activation(user) > > > redirect_to... and return #this is where a validated user should > > > go > > > else > > > flash[:error] = "Invalid Activation Code" > > > redirect_to... #or do whatever you want here when someone has an > > > invalid code > > > end > > > end > > > > This isn''t 1000% secure, it doesn''t actually match the user with the > > > code, etc. But it''s good enough for me. If it''s not good enough for > > > you then it''s easy enough to adapt. > > > > Of course, you need a standard ActiveMailer model and view. ''user'' > > > will be passed to it. > > > > On Apr 25, 6:25 am, Saurav Chakraborty <rails-mailing-l...@andreas- > > > > s.net> wrote: > > > > Hi all, > > > > > I need a help. I have got a user registration form, where the user signs > > > > up and then an activation link is sent to the user email id for > > > > activating his/her account. Now I need to send an another email to the > > > > user, only after he logs in for the first time in my site, then the > > > > second email should be sent. Can anybody give me some suggestion on how > > > > to do it ?? > > > > > NB: When the user clicks on the activation link, he is not directed to > > > > user home page, only the home page of my website is displayed. > > > > > Thanks > > > > Saurav > > > > -- > > > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> class UserObserver < ActiveRecord::Observer > def after_create(user) > UserMailer.deliver_signup_notification(user) > end > > def after_save(user) > > UserMailer.deliver_activation(user) if user.pending? > > end > endBro, it''s simple question. What do you call for after_create or after_save? is it called trigger? if yes, can i write trigger in modul? or helper? Thanks, Reint -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---