]> git.openstreetmap.org Git - rails.git/commitdiff
Add additional validation to the user model and tidy up a few things on
authorTom Hughes <tom@compton.nu>
Sun, 19 Aug 2007 12:27:23 +0000 (12:27 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 19 Aug 2007 12:27:23 +0000 (12:27 +0000)
the account options page.

app/controllers/user_controller.rb
app/models/user.rb
app/views/user/account.rhtml

index 5c95de0c9cad315e69830f3dff116e198e4386f4..e69ce313723431055e57b2e70a7c722b78251632 100644 (file)
@@ -33,8 +33,8 @@ class UserController < ApplicationController
         @user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation]
       end
       @user.description = params[:user][:description]
-      @user.home_lat = home_lat.to_f
-      @user.home_lon = home_lon.to_f
+      @user.home_lat = home_lat
+      @user.home_lon = home_lon
       if @user.save
         flash[:notice] = "User information updated successfully."
       else
index ef8e8bbf70aca4a2215a6cf7758fac913d7b2e54..83a8194ddb78b6ed2389df29a7ee5f5e3ff0b43e 100644 (file)
@@ -9,6 +9,7 @@ class User < ActiveRecord::Base
   has_many :tokens, :class_name => "UserToken"
   has_many :preferences, :class_name => "UserPreference"
 
+  validates_presence_of :email, :display_name
   validates_confirmation_of :pass_crypt, :message => 'Password must match the confirmation password'
   validates_uniqueness_of :display_name, :allow_nil => true
   validates_uniqueness_of :email
@@ -16,6 +17,9 @@ class User < ActiveRecord::Base
   validates_length_of :display_name, :minimum => 3, :allow_nil => true
   validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
   validates_format_of :display_name, :with => /^[^\/;.,?]*$/
+  validates_numericality_of :home_lat, :allow_nil => true
+  validates_numericality_of :home_lon, :allow_nil => true
+  validates_numericality_of :home_zoom, :only_integer => true, :allow_nil => true
 
   before_save :encrypt_password
 
index 54702ace9a04b149a685ef3008b15926f73afb29..99253471d1f38b7ee0efac428d776563f1badb7e 100644 (file)
@@ -1,16 +1,16 @@
 <h2>User details</h2>
 <%= error_messages_for 'user' %>
-<% form_tag :controller => 'user', :action => 'account', :display_name => @user.display_name do %>
+<% form_for :user, @user do |f| %>
 <table style="width : 100%">
   <tr><td>Email</td><td><%= @user.email %></td></tr>
   <tr><td>Mapper since</td><td><%= @user.creation_time %> (<%= time_ago_in_words(@user.creation_time) %> ago)</td></tr>
-  <tr><td>Display Name</td><td><%= text_field :user, :display_name, :value => @user.display_name %></td></tr>
-  <tr><td>Password</td><td><%= password_field('user', 'pass_crypt',{:value => '', :size => 50, :maxlength => 255}) %></td></tr>
-  <tr><td>Confirm Password</td><td><%= password_field('user', 'pass_crypt_confirmation',{:value => '', :size => 50, :maxlength => 255}) %></td></tr>
+  <tr><td>Display Name</td><td><%= f.text_field :display_name %></td></tr>
+  <tr><td>Password</td><td><%= f.password_field :pass_crypt, {:value => '', :size => 50, :maxlength => 255} %></td></tr>
+  <tr><td>Confirm Password</td><td><%= f.password_field :pass_crypt_confirmation, {:value => '', :size => 50, :maxlength => 255} %></td></tr>
 
-  <tr><td valign="top">Description</td><td><%= text_area :user, :description, :value => @user.description, :class => "editDescription" %></td></tr>
+  <tr><td valign="top">Description</td><td><%= f.text_area :description, :class => "editDescription" %></td></tr>
 
-  <tr id="homerow" <% unless @user.home_lat and @user.home_lon %> class="nohome" <%end%> ><td>Your home</td><td><em class="message">You have not entered your home location.</em><span class="location">Latitude: <%= text_field :user, :home_lat, :value => @user.home_lat, :size => 20, :id => "home_lat" %> Longitude <%= text_field :user, :home_lon, :value => @user.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>Your home</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><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>
 <% else %>
   Currently your edits are anonymous and people can't find out where you are located. To show what you edited and allow people to contact you through the website, click the button below. This action cannot be reversed.
   <br /><br />
-  <% form_tag :controller => 'user', :action => 'go_public' do %>
-  <%= submit_tag 'Make all my edits public, forever' %>
-  <% end %>
+  <%= button_to "Make all my edits public, forever", :action => :go_public %>
 <% end %>