class UserController < ApplicationController
-
+ layout 'site'
+
def save
@user = User.new(params[:user])
@user.set_defaults
if @user.save
- flash[:notice] = 'Users was successfully created.'
+ flash[:notice] = 'User was successfully created. Check your email for a confirmation note, and you\'ll be mapping in no time :-)'
Notifier::deliver_signup_confirm(@user)
redirect_to :action => 'login'
else
end
end
+ def lost_password
+ if params['user']['email']
+ user = User.find_by_email(params['user']['email'])
+ if user
+ user.token = User.make_token
+ user.save
+ Notifier::deliver_lost_password(user)
+ flash[:notice] = "Sorry you lost it :-( but an email is on it's way so you can reset it soon."
+ else
+ flash[:notice] = "Couldn't find that email address, sorry."
+ end
+ end
+ end
+
def new
- render :layout => 'site'
end
def login
session[:token] = u.token
redirect_to :controller => 'site', :action => 'index'
return
+ else
+ flash[:notice] = "Couldn't log in with those details"
end
end
-
- render :layout => 'site'
end
def logout
if @user && @user.active == 0
@user.active = true
@user.save
- flash[:notice] = 'Confirmed your account'
+ flash[:notice] = 'Confirmed your account, thanks for signing up!'
#FIXME: login the person magically
class Notifier < ActionMailer::Base
def signup_confirm( user )
- # Email header info MUST be added here
@recipients = user.email
@from = 'abuse@openstreetmap.org'
@subject = '[OpenStreetMap] Confirm your email address'
-
@body['url'] = 'http://www.openstreetmap.org/user/confirm?confirm_string=' + user.token
end
-
+
+ def lost_password( user )
+ @recipients = user.email
+ @from = 'abuse@openstreetmap.org'
+ @subject = '[OpenStreetMap] Passwors reset request'
+ @body['url'] = "http://www.openstreetmap.org/user/reset_password?email=#{user.email}&token=#{user.token}"
+ end
+
end
find_first([ "token = ? ", token])
end
- def self.make_token
+ def self.make_token(length=30)
chars = 'abcdefghijklmnopqrtuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
confirmstring = ''
- 30.times do
+ length.times do
confirmstring += chars[(rand * chars.length).to_i].chr
end
<span id="greeting">
<% if @user %>
- Welcome, <%= @user.email %> |
- <%= link_to 'Logout', {:controller => 'user', :action => 'logout'}, {:id => 'loginanchor'}%>
+ Welcome, <%= @user.display_name %> |
+ <%= link_to 'logout', {:controller => 'user', :action => 'logout'}, {:id => 'loginanchor'}%>
<% else %>
- <%= link_to 'Login', {:controller => 'user', :action => 'login'}, {:id => 'loginanchor'}%> |
- <%= link_to 'Sign up', {:controller => 'user', :action => 'new'}, {:id => 'registeranchor'} %>
+ <%= link_to 'log in', {:controller => 'user', :action => 'login'}, {:id => 'loginanchor'}%> |
+ <%= link_to 'sign up', {:controller => 'user', :action => 'new'}, {:id => 'registeranchor'} %>
<% end %>
</span>
--- /dev/null
+Hi,
+
+Someone (possibly you) has asked for the password to be reset on this
+email addresses openstreetmap.org account.
+
+If this is you, please click the link below to reset your password.
+
+<%= @url %>
<%= start_form_tag :action => 'login' %>
<table>
- <tr><td>Login name</td><td><%= text_field('user', 'email',{:size => 50, :maxlength => 255}) %></td></tr>
+ <tr><td>email address:</td><td><%= text_field('user', 'email',{:size => 50, :maxlength => 255}) %></td></tr>
<tr><td>password:</td><td><%= password_field('user', 'password',{:size => 50, :maxlength => 255}) %></td></tr>
</table>
<br>
<input type="submit" value="Login">
-<%= end_form_tag %> (<%= link_to 'Forgotten your password?', :controller => 'user', :action => 'lost_password' %>)
+<%= end_form_tag %> (<%= link_to 'Lost your password?', :controller => 'user', :action => 'lost_password' %>)
--- /dev/null
+<h1>Forgotten Password?</h1><br>
+
+<%= start_form_tag :action => 'lost_password' %>
+<table>
+ <tr><td>email address:</td><td><%= text_field('user', 'email', {:size => 50, :maxlength => 255} ) %></td></tr>
+</table>
+<br>
+<input type="submit" value="Send me a new password">
<h1>Create a user account</h1><br>
Fill in the form and we'll send you a quick email to activate your account.<br><br>
-By creating an account, you agree that all work uploaded to openstreetmap.org and all data created by use of any tools on openstreetmap.org is to be licensed under <a href="http://creativecommons.org/licenses/by-sa/2.0/">this</a> Creative Commons license.<br><br>
+By creating an account, you agree that all work uploaded to openstreetmap.org and all data created by use of any tools which connect to openstreetmap.org is to be licensed under this <a href="http://creativecommons.org/licenses/by-sa/2.0/">this Creative Commons license (by-sa)</a>.<br><br>
<%= error_messages_for 'user' %>
<%= start_form_tag :action => 'save' %>
<table>
- <tr><td>email address:</td><td><%= text_field('user', 'email',{:size => 50, :maxlength => 255}) %></td></tr>
- <tr><td>Login name</td><td><%= text_field('user', 'display_name',{:size => 50, :maxlength => 255}) %></td></tr>
+ <tr><td>email:</td><td><%= text_field('user', 'email',{:size => 50, :maxlength => 255}) %></td></tr>
+ <tr><td>login name</td><td><%= text_field('user', 'display_name',{:size => 50, :maxlength => 255}) %></td></tr>
<tr><td>password:</td><td><%= password_field('user', 'pass_crypt',{:size => 50, :maxlength => 255}) %></td></tr>
<tr><td>retype password:</td><td><%= password_field('user', 'pass_crypt_confirmation',{:size => 50, :maxlength => 255}) %></td></tr>
</table>
map.connect '/login.html', :controller => 'user', :action => 'login'
map.connect '/logout.html', :controller => 'user', :action => 'logout'
map.connect '/create-account.html', :controller => 'user', :action => 'new'
+ map.connect '/forgot-password.html', :controller => 'user', :action => 'lost_password'
map.connect ':controller/:action/:id'
end
-\r
a {\r
color: #0000ff;\r
text-decoration: none;\r
\r
#notice {\r
width: 400px;\r
- border: 2px solid green;\r
+ border: 1px solid black;\r
padding: 7px;\r
- padding-bottom: 12px;\r
- margin-bottom: 20px;\r
background-color: #f0f0f0;\r
}\r
\r
list-style: square;\r
}\r
\r
+input {\r
+ border: 1px solid black;\r
+}\r