Permalink
Browse files

Merge branch 'working'

  • Loading branch information...
2 parents dcfb6de + 8ef8f44 commit e7f699bd064bb0f9bce1cac3a2c914eb7cd497f1 @davesag davesag committed Sep 23, 2010
@@ -13,22 +13,40 @@
class RegistrationHandler < Frank
-# TODO: notify the user with that email
+# utility method to actually send the email. uses a haml template for HTML email and erb for plain text.
+ def send_email_to_user(user, subject, body_template, template_locals)
+ puts "user wants html email = " + user.get_preference("HTML_EMAIL").value
+ if user.get_preference("HTML_EMAIL").value == 'true'
+ puts "sending HTML email to " + user.email
+ email_body = haml(body_template, :locals => template_locals )
+ type = 'text/html'
+ else
+ puts "sending plain text email to " + user.email
+ email_body = erb(body_template, :locals => template_locals)
+ type = 'text/plain'
+ end
+ Pony.mail :to => user.email,
+ :from => "frank_test@davesag.com",
+ :subject => subject,
+ :headers => { 'Content-Type' => type },
+ :body => email_body
+ end
+
+# notify the user with that email
def notify_user_of_registration_overlap_attempt!(email,supplied_name)
user = User.find_by_email(email)
- # send the email
+ template_locals = { :user => user, :supplied_name => supplied_name}
+ send_email_to_user(user,"Frank says someone is using your email." ,:'mail/email_warning', template_locals)
end
-# TODO: generate a confirmation url and email and send it to the user.
+# generate a confirmation url and email and send it to the user.
def send_confirmation_to(user)
token_link = "http://localhost:9292/validate/" + user.validation_token
- Pony.mail :to => user.email,
- :from => "frank_test@davesag.com",
- :subject => "Frank says Please verify your email.",
- :body => "Please click on " + token_link + " to verify your registration."
+ template_locals = { :user => user, :token_url => token_link}
+ send_email_to_user(user,"Frank requests that you verify your email address." ,:'mail/new_registration', template_locals)
end
- #registration action - check username and email are unique and valid and display 'check your email' page
+# registration action - check username and email are unique and valid and display 'check your email' page
post '/registration' do
if is_logged_in?
haml :'in/index', :locals => { :message => "You are already logged in as", :user => active_user }
@@ -16,7 +16,7 @@ class UserHandler < Frank
if is_logged_in?
name = active_user.username
log_user_out
- haml :login, :locals => { :message => "Thanks for visiting #{name}. Please log in again to continue", :name => "" }
+ haml :login, :locals => { :message => "Thanks for visiting #{name}. Please log in again to continue", :name => "#{name}" }
else
haml :login, :locals => { :message => "You were not logged in. Please log in to continue", :name => "" }
end
View
@@ -6,7 +6,15 @@
%body
#header
/ template header content goes here
+ %h2 Let me be Frank.
#content
= yield
#footer
/ template footer content goes here
+ [
+ %a{:href=>'/'}Home
+ |
+ %a{:href=>'/'}Log in
+ |
+ %a{:href=>'/'}Register
+ ]
View
@@ -2,11 +2,11 @@
%form(accept-charset='UTF-8' action='/login' method='post')
%p<
%label{ :for => "username" }Username
- %input(name='username' type='text')
+ %input(name='username' type='text' value='#{name}')
%p<
%label{ :for => "password" }Password
%input(name='password' type='password')
%input(type='submit' value='Log In')
%p
Or please
- %a{ :href => "/register" } register
+ %a{ :href => "/register" }register
@@ -0,0 +1,11 @@
+Dear <%= user.username%>,
+
+Someone giving the username '<%= supplied_name%>' just tried to register with Frank using your email address.
+
+Just thought you'd like to know.
+
+Cheers
+
+Frank
+
+Sent by http://github.com/davesag/Frank
@@ -0,0 +1,11 @@
+%p Dear #{user.username},
+%p
+ Someone giving the username '#{supplied_name}' just tried to register with
+ %a{ :href => 'http://github.com/davesag/Frank' }Frank
+ using your email address.
+%p Just thought you'd like to know.
+%p Cheers
+%p Frank
+%p
+ Sent by
+ %a{ :href => 'http://github.com/davesag/Frank' }Frank
@@ -1,6 +1,6 @@
-Dear <%= @user.username%>,
+Dear <%= user.username%>,
-Thank's for registering. Please click <%= @token_url%> to validate your email.
+Thank's for registering. Please click <%= token_url%> to validate your registration and then log in.
Cheers
@@ -1,9 +1,10 @@
%p Dear #{user.username},
%p
- Thank's for registering. Please click
- %a{ :href => "http://localhost:4567/verify/#{user.registration_token" }
+ Thanks for registering. Please click
+ %a{ :href => token_url }this link
+ to confirm your registration and then log in.
%p Cheers
%p Frank
%p
Sent by
- %a{ :href => 'http://github.com/davesag/Frank' }
+ %a{ :href => 'http://github.com/davesag/Frank' }Frank
View
@@ -5,7 +5,7 @@
%input(name='email' type='text')
%p<
%label{ :for => "username" }Choose a username
- %input(name='username' type='text')
+ %input(name='username' type='text' value='#{name}')
%p<
%label{ :for => "password" }Choose a Password
%input(name='password' type='password')

0 comments on commit e7f699b

Please sign in to comment.