Some more of the user account translations. Custom generate method for languages, that doesn't appear to work. Setting user language on create. Start translations in controllers. Diary entries can now be saved.

This commit is contained in:
Shaun McDonald 2009-05-30 14:04:42 +00:00
parent a6f88faa20
commit 3a599519eb
7 changed files with 93 additions and 38 deletions

View file

@ -13,6 +13,8 @@ class DiaryEntryController < ApplicationController
if params[:diary_entry] if params[:diary_entry]
@diary_entry = DiaryEntry.new(params[:diary_entry]) @diary_entry = DiaryEntry.new(params[:diary_entry])
@diary_entry.user = @user @diary_entry.user = @user
@diary_entry.language = Language.find_by_code(params[:language])
@diary_entry.language = Language.find_by_code("en") if @diary_entry.language.nil?
if @diary_entry.save if @diary_entry.save
redirect_to :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name redirect_to :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name
@ -31,6 +33,8 @@ class DiaryEntryController < ApplicationController
if @user != @diary_entry.user if @user != @diary_entry.user
redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id] redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
elsif params[:diary_entry] elsif params[:diary_entry]
params[:diary_entry][:language] = Language.find_by_code(params[:diary_entry][:language])
params[:diary_entry][:language] = Language.find_by_code("en") if params[:diary_entry][:language].nil?
if @diary_entry.update_attributes(params[:diary_entry]) if @diary_entry.update_attributes(params[:diary_entry])
redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id] redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
end end

View file

@ -23,9 +23,11 @@ class UserController < ApplicationController
@user.data_public = true @user.data_public = true
@user.description = "" if @user.description.nil? @user.description = "" if @user.description.nil?
@user.creation_ip = request.remote_ip @user.creation_ip = request.remote_ip
@user.locale = Language.find_by_code(I18n.locale.to_s)
@user.locale = Language.find_by_code("en") if @user.locale.nil?
if @user.save if @user.save
flash[:notice] = "User was successfully created. Check your email for a confirmation note, and you\'ll be mapping in no time :-)<br /><br />Please note that you won't be able to login until you've received and confirmed your email address.<br /><br />If you use an antispam system which sends confirmation requests then please make sure you whitelist webmaster@openstreetmap.org as we are unable to reply to any confirmation requests." flash[:notice] = I18n.t('user.new.create success message')
Notifier.deliver_signup_confirm(@user, @user.tokens.create) Notifier.deliver_signup_confirm(@user, @user.tokens.create)
redirect_to :action => 'login' redirect_to :action => 'login'
else else
@ -54,10 +56,10 @@ class UserController < ApplicationController
if @user.save if @user.save
if params[:user][:email] == @user.new_email if params[:user][:email] == @user.new_email
@notice = "User information updated successfully. Check your email for a note to confirm your new email address." flash[:notice] = I18n.t('user.account.flash update success confirm needed')
Notifier.deliver_email_confirm(@user, @user.tokens.create) Notifier.deliver_email_confirm(@user, @user.tokens.create)
else else
@notice = "User information updated successfully." flash[:notice] = I18n.t('user.account.flash update success')
end end
end end
end end
@ -68,7 +70,7 @@ class UserController < ApplicationController
@user.home_lat = params[:user][:home_lat].to_f @user.home_lat = params[:user][:home_lat].to_f
@user.home_lon = params[:user][:home_lon].to_f @user.home_lon = params[:user][:home_lon].to_f
if @user.save if @user.save
flash[:notice] = "Home location saved successfully." flash[:notice] = I18n.t('user.set_home.flash success')
redirect_to :controller => 'user', :action => 'account' redirect_to :controller => 'user', :action => 'account'
end end
end end
@ -77,27 +79,27 @@ class UserController < ApplicationController
def go_public def go_public
@user.data_public = true @user.data_public = true
@user.save @user.save
flash[:notice] = 'All your edits are now public.' flash[:notice] = I18n.t('user.go_public.flash success')
redirect_to :controller => 'user', :action => 'account', :display_name => @user.display_name redirect_to :controller => 'user', :action => 'account', :display_name => @user.display_name
end end
def lost_password def lost_password
@title = 'lost password' @title = I18n.t('user.lost_password.title')
if params[:user] and params[:user][:email] if params[:user] and params[:user][:email]
user = User.find_by_email(params[:user][:email], :conditions => {:visible => true}) user = User.find_by_email(params[:user][:email], :conditions => {:visible => true})
if user if user
token = user.tokens.create token = user.tokens.create
Notifier.deliver_lost_password(user, token) Notifier.deliver_lost_password(user, token)
@notice = "Sorry you lost it :-( but an email is on its way so you can reset it soon." flash[:notice] = I18n.t('user.lost_password.notice.email on way')
else else
@notice = "Couldn't find that email address, sorry." flash[:notice] = I18n.t('user.lost_password.notice email cannot find')
end end
end end
end end
def reset_password def reset_password
@title = 'reset password' @title = I18n.t('user.reset_password.title')
if params['token'] if params['token']
token = UserToken.find_by_token(params[:token]) token = UserToken.find_by_token(params[:token])
if token if token
@ -110,9 +112,9 @@ class UserController < ApplicationController
user.save! user.save!
token.destroy token.destroy
Notifier.deliver_reset_password(user, pass) Notifier.deliver_reset_password(user, pass)
flash[:notice] = "Your password has been changed and is on its way to your mailbox :-)" flash[:notice] = I18n.t('user.reset_password.flash changed check mail')
else else
flash[:notice] = "Didn't find that token, check the URL maybe?" flash[:notice] = I18n.t('user.reset_password.flash token bad')
end end
end end

View file

@ -3,4 +3,12 @@ class Language < ActiveRecord::Base
has_many :users, :foreign_key => 'locale' has_many :users, :foreign_key => 'locale'
has_many :diary_entries, :foreign_key => 'language' has_many :diary_entries, :foreign_key => 'language'
def self.generate(code, name, translation_available)
Language.create do |l|
l.code = code
l.name = name
l.translation_available = translation_available
end
end
end end

View file

@ -1,33 +1,33 @@
<h2>My settings</h2> <h2><%= t 'user.account.my settings' %></h2>
<%= error_messages_for 'user' %> <%= error_messages_for 'user' %>
<% form_for :user, @user do |f| %> <% form_for :user, @user do |f| %>
<table id="accountForm"> <table id="accountForm">
<tr><td class="fieldName">Display Name : </td><td><%= f.text_field :display_name %></td></tr> <tr><td class="fieldName"><%= t 'user.new.display name' %></td><td><%= f.text_field :display_name %></td></tr>
<tr><td class="fieldName">Email : </td><td><%= f.text_field :email, {:size => 50, :maxlength => 255} %> <span class="minorNote">(never displayed publicly)</span></td></tr> <tr><td class="fieldName"><%= t 'user.new.email address' %></td><td><%= f.text_field :email, {:size => 50, :maxlength => 255} %> <span class="minorNote"><%= t 'user.account.email never displayed publicly' %></span></td></tr>
<tr><td class="fieldName" style="padding-bottom:0px;">Password : </td><td style="padding-bottom:0px;"><%= f.password_field :pass_crypt, {:value => '', :size => 30, :maxlength => 255} %></td></tr> <tr><td class="fieldName" style="padding-bottom:0px;"><%= t 'user.new.password' %></td><td style="padding-bottom:0px;"><%= f.password_field :pass_crypt, {:value => '', :size => 30, :maxlength => 255} %></td></tr>
<tr><td class="fieldName">Confirm Password : </td><td><%= f.password_field :pass_crypt_confirmation, {:value => '', :size => 30, :maxlength => 255} %></td></tr> <tr><td class="fieldName"><%= t 'user.new.confirm password' %></td><td><%= f.password_field :pass_crypt_confirmation, {:value => '', :size => 30, :maxlength => 255} %></td></tr>
<tr> <tr>
<td class="fieldName" valign="top">Public editing :</td> <td class="fieldName" valign="top"><%= t 'user.account.public editing.heading' %></td>
<td> <td>
<% if @user.data_public? %> <% if @user.data_public? %>
Enabled. Not anonymous <span class="minorNote">(<a href="http://wiki.openstreetmap.org/index.php/Disabling_anonymous_edits" target="_new">what's this?</a>)</span> <%= t 'user.account.public editing.enabled' %> <span class="minorNote">(<a href="<%= t 'user.account.public editing.enabled link' %>" target="_new"><%= t 'user.account.public editing.enabled link text' %></a>)</span>
<% else %> <% else %>
Disabled and anonymous. <span class="minorNote">(<a href="#public">why's this bad?</a>)</span> <%= t 'user.account.public editing.disabled' %><span class="minorNote">(<a href="#public"><%= t 'user.account.public editing.disabled link text' %></a>)</span>
<% end %> <% end %>
</td> </td>
</tr> </tr>
<tr><td class="fieldName" valign="top">Profile Description : </td><td><%= f.text_area :description, :rows => '5', :cols => '60' %><br /><br /></td></tr> <tr><td class="fieldName" valign="top"><%= t 'user.account.profile description' %></td><td><%= f.text_area :description, :rows => '5', :cols => '60' %><br /><br /></td></tr>
<tr id="homerow" <% unless @user.home_lat and @user.home_lon %> class="nohome" <%end%> ><td class="fieldName">Home Location : </td><td><em class="message">You have not entered your home location.</em><span class="location">Latitude: <%= f.text_field :home_lat, :size => 20, :id => "home_lat" %> Longitude <%= f.text_field :home_lon, :size => 20, :id => "home_lon" %></span></td></tr> <tr id="homerow" <% unless @user.home_lat and @user.home_lon %> class="nohome" <%end%> ><td class="fieldName"><%= t 'user.account.home location' %></td><td><em class="message"><%= t 'user.account.no home location' %></em><span class="location"><%= t 'user.account.latitude' %> <%= f.text_field :home_lat, :size => 20, :id => "home_lat" %><%= t 'user.account.longitude' %><%= f.text_field :home_lon, :size => 20, :id => "home_lon" %></span></td></tr>
<tr><td></td><td> <tr><td></td><td>
<p>Update home location when I click on the map? <input type="checkbox" value="1" <% unless @user.home_lat and @user.home_lon %> checked="checked" <% end %> id="updatehome" /> </p> <p><%= t 'user.account.update home location on click' %> <input type="checkbox" value="1" <% unless @user.home_lat and @user.home_lon %> checked="checked" <% end %> id="updatehome" /> </p>
<div id="map" style="border:1px solid black; position:relative; width:500px; height:400px;"></div> <div id="map" style="border:1px solid black; position:relative; width:500px; height:400px;"></div>
</td></tr> </td></tr>
<tr><td></td><td align=right><br/></br><%= submit_tag 'Save Changes' %></td></tr> <tr><td></td><td align=right><br/></br><%= submit_tag t('user.account.save changes button') %></td></tr>
</table> </table>
<br/> <br/>
@ -42,10 +42,10 @@
Your email address will not be revealed by becoming public.<br /> Your email address will not be revealed by becoming public.<br />
This action cannot be reversed and all new users are now public by default.<br /> This action cannot be reversed and all new users are now public by default.<br />
<br /><br /> <br /><br />
<%= button_to "Make all my edits public", :action => :go_public %> <%= button_to t('user.account.make all my edits public button', :action => :go_public %>
<% end %> <% end %>
<br/> <br/>
<br/> <br/>
<%= link_to 'return to profile', :controller => 'user', :action => @user.display_name %> <%= link_to t('user.account.return to profile'), :controller => 'user', :action => @user.display_name %>
<br/> <br/>
<br/> <br/>

View file

@ -1,10 +1,10 @@
<h1>Confirm a user account</h1> <h1><%= t 'user.confirm.heading' %></h1>
<p>Press the confirm button below to activate your account.</p> <p><%= t 'user.confirm.press confirm button' %></p>
<form method="post"> <form method="post">
<input type="hidden" name="confirm_string" value="<%= params[:confirm_string] %>"> <input type="hidden" name="confirm_string" value="<%= params[:confirm_string] %>">
<input type="submit" name="confirm_action" value="Confirm"> <input type="submit" name="confirm_action" value="<%= t 'user.confirm.button' %>">
</form> </form>

View file

@ -1,8 +1,8 @@
<h1>Confirm a change of email address</h1> <h1><%= t 'user.confirm email.heading' %></h1>
<p>Press the confirm button below to confirm your new email address.</p> <p><%= t 'user.confirm email. press confirm button' %></p>
<form method="post"> <form method="post">
<input type="hidden" name="confirm_string" value="<%= params[:confirm_string] %>"> <input type="hidden" name="confirm_string" value="<%= params[:confirm_string] %>">
<input type="submit" name="confirm_action" value="Confirm"> <input type="submit" name="confirm_action" value="<%= t 'user.confirm email.button' %>">
</form> </form>

View file

@ -12,12 +12,12 @@ en:
older_entries: Older Entries older_entries: Older Entries
newer_entries: Newer Entries newer_entries: Newer Entries
edit: edit:
subject: "Subject:" subject: "Subject: "
body: "Body:" body: "Body: "
language: "Language:" language: "Language: "
location: "Location:" location: "Location: "
latitude: "Latitude:" latitude: "Latitude: "
longitude: "Longitude:" longitude: "Longitude: "
use_map_link: "use map" use_map_link: "use map"
save_button: "Save" save_button: "Save"
marker_text: Diary entry location marker_text: Diary entry location
@ -96,9 +96,16 @@ en:
lost password link: "Lost your password?" lost password link: "Lost your password?"
login_button: Login login_button: Login
lost_password: lost_password:
title: lost password
heading: "Forgotten Password?" heading: "Forgotten Password?"
email address: "Email Address:" email address: "Email Address:"
new password button: "Send me a new password" new password button: "Send me a new password"
notice email on way: "Sorry you lost it :-( but an email is on its way so you can reset it soon."
notice email cannot find: "Couldn't find that email address, sorry."
reset_password:
title: reset password
flash changed check mail: "Your password has been changed and is on its way to your mailbox :-)"
flash token bad: "Didn't find that token, check the URL maybe?"
new: new:
heading: Create a User Account heading: Create a User Account
no_auto_account_create: "Unfortunately we are not currently able to create an account for you automatically." no_auto_account_create: "Unfortunately we are not currently able to create an account for you automatically."
@ -109,9 +116,10 @@ en:
confirm email address: "Confirm Email Address: " confirm email address: "Confirm Email Address: "
not displayed publicly: 'Not displayed publicly (see <a href="http://wiki.openstreetmap.org/wiki/Privacy_Policy" title="wiki privacy policy including section on email addresses">privacy policy</a>)' not displayed publicly: 'Not displayed publicly (see <a href="http://wiki.openstreetmap.org/wiki/Privacy_Policy" title="wiki privacy policy including section on email addresses">privacy policy</a>)'
display name: "Display Name: " display name: "Display Name: "
password: "Password: " pasword: "Password: "
confirm password: "Confirm Password: " confirm password: "Confirm Password: "
signup: Signup signup: Signup
flash create success message: "User was successfully created. Check your email for a confirmation note, and you\'ll be mapping in no time :-)<br /><br />Please note that you won't be able to login until you've received and confirmed your email address.<br /><br />If you use an antispam system which sends confirmation requests then please make sure you whitelist webmaster@openstreetmap.org as we are unable to reply to any confirmation requests."
no_such_user: no_such_user:
body: "Sorry, there is no user with the name {{user}}. Please check your spelling, or maybe the link you clicked is wrong." body: "Sorry, there is no user with the name {{user}}. Please check your spelling, or maybe the link you clicked is wrong."
view: view:
@ -145,3 +153,36 @@ en:
friend_map: friend_map:
your location: Your location your location: Your location
nearby mapper: "Nearby mapper: " nearby mapper: "Nearby mapper: "
account:
my settings: My settings
email never displayed publicly: "(never displayed publicly)"
public editing:
heading: "Public editing: "
enabled: "Enabled. Not anonymous and can edit data."
enabled link: "http://wiki.openstreetmap.org/wiki/Disabling_anonymous_edits"
enabled link text: "what's this?"
disabled: "Disabled and cannot edit data, all previous edits are anonymous."
disabled link text: "why can't I edit?"
profile description: "Profile Description: "
home location: "Home Location: "
no home location: "You have not entered your home location."
latitude: "Latitude: "
longitude: "Longitude: "
update home location on click: "Update home location when I click on the map?"
save changes button: Save Changes
make edits public button: Make all my edits public
return to profile: Return to profile
flash update success confirm needed: "User information updated successfully. Check your email for a note to confirm your new email address."
flash update success: "User information updated successfully."
confirm:
heading: Confirm a user account
press confirm button: "Press the confirm button below to activate your account."
button: Confirm
confirm email:
heading: Confirm a change of email address
press confirm button: "Press the confirm button below to confirm your new eail address."
button: Confirm
set_home:
flash success: "Home location saved successfully"
go_public:
flash success: "All your edits are now public, and you are now allowed to edit."