]> git.openstreetmap.org Git - rails.git/commitdiff
more rails updates
authorSteve Coast <steve@asklater.com>
Tue, 1 Aug 2006 17:50:10 +0000 (17:50 +0000)
committerSteve Coast <steve@asklater.com>
Tue, 1 Aug 2006 17:50:10 +0000 (17:50 +0000)
app/controllers/node_controller.rb
app/controllers/user_controller.rb
app/models/node.rb
app/models/user.rb
app/views/layouts/user.rhtml
app/views/user/confirm.rhtml [new file with mode: 0644]
app/views/user/new.rhtml
app/views/user/save.rhtml [moved from app/views/user/signup.rhtml with 100% similarity]
public/stylesheets/site.css

index cafc0f00f46eeee755ba6d0bad1b7481e08c5465..6092ddd9deadfbf3362ea4212fa047c60ba1ee73 100644 (file)
@@ -4,6 +4,13 @@ class NodeController < ApplicationController
   before_filter :authorize
 
   def create
+    @node = Node.new
+    @node.id = 1
+    @node.latitude = 1
+    @node.save
+  end
+
+  def dummy
     if request.post?
       userid = dao.useridfromcreds(r.user, r.get_basic_auth_pw)
       doc = Document.new $stdin.read
index 7a0c8b3d70c8cf6837ebe8f8fa2afb492550f2d4..b982a93c9863f094185983e067a9abd8b22d70c2 100644 (file)
@@ -2,11 +2,32 @@ class UserController < ApplicationController
 
   def save
     @user = User.new(params[:user])
-#    @user.save
-    #Notifier::deliver_confirm_signup(user)
+    @user.set_defaults
+
+    if @user.save
+      flash[:notice] = 'Users was successfully created.'
+      Notifier::deliver_signup_confirm(@user)
+      redirect_to :action => 'login'
+    else
+      render :action => 'new'
+    end
+
   end
-  
+
   def new
 
   end
+
+  def confirm
+    @user = User.find_by_token(params[:confirm_string])
+    if @user && @user.active == 0
+      @user.active = true
+      @user.save
+      flash[:notice] = 'Confirmed your account'
+      redirect_to :action => 'login'
+    else
+      flash[:notice] = 'Something went wrong confirming that user'
+    end
+  end
+
 end
index 914e90b7eb43db78c5c2c4bfb29e25602d4d269d..d1bedd03cdf5f8284227ecab0675513847f34de5 100644 (file)
@@ -1,4 +1,6 @@
 class Node < ActiveRecord::Base
   set_table_name 'current_nodes'
+
   belongs_to :user
+
 end
index 72752078e3aa441fec1f51b4bfa5a14bef41f8ba..1a12790420a899473de6c4c56fc890a0874e0fd5 100644 (file)
@@ -3,20 +3,43 @@ require 'digest/md5'
 class User < ActiveRecord::Base
   has_many :traces
 
-  validates_confirmation_of :pass_crypt
+  validates_confirmation_of :pass_crypt, :message => 'Password must match the confirmation password'
+  validates_uniqueness_of :display_name
+  validates_uniqueness_of :email
+  validates_length_of :pass_crypt, :minimum => 8
+  validates_length_of :display_name, :minimum => 3
+  validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
 
-#  def password=(str) 
-#    write_attribute("pass_crypt", Digest::MD5.hexdigest(str)) 
-#  end 
+  def set_defaults
+    self.creation_time = Time.now
+    self.timeout = Time.now
+    self.token = make_token()
+  end
+  
+  def pass_crypt=(str) 
+    write_attribute("pass_crypt", Digest::MD5.hexdigest(str)) 
+  end 
 
+  def pass_crypt_confirmation=(str) 
+    write_attribute("pass_crypt_confirm", Digest::MD5.hexdigest(str)) 
+  end 
 
-#  def password
-#    return self.pass_crypt
-#  end 
+  def self.authenticate(email, passwd) 
+    find_first([ "email = ? AND pass_crypt =?", 
+               email, 
+               Digest::MD5.hexdigest(passwd) ]) 
+  end 
+  
+  private
+  def make_token
+    chars = 'abcdefghijklmnopqrtuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
+    confirmstring = ''
+
+    30.times do
+      confirmstring += chars[(rand * chars.length).to_i].chr
+    end
+
+    return confirmstring
+  end
 
-#  def self.authenticate(username, passwd) 
-#    find_first([ "display_name = ? AND pass_crypt =?", 
-#               username, 
-#               Digest::MD5.hexdigest(passwd) ]) 
-#  end 
 end
index 3d8287fcd07a1bc4ba79247caae674135da77668..cee649145e812541f837d28b8804f30d6442a982 100644 (file)
   <body>
 
     <div id="content">
+<% if @flash[:notice] %>
+  <div id="notice"><%= @flash[:notice] %></div>
+<% end %>
+
     <%= @content_for_layout %>
 
   </div>
diff --git a/app/views/user/confirm.rhtml b/app/views/user/confirm.rhtml
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
index 00ab2c7d8bf55fc54834d64ac148606f2f83406c..bc237f0a96a1153fbc0506cf5f4d8b1d761b2db0 100644 (file)
@@ -3,6 +3,8 @@ Fill in the form and we'll send you a quick email to activate your account.<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>
 
+<%= 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>
index 0dc7eaf18881a6c1122b8e0b238a7ba0379b7d31..9b29cd806f39b47a078d785a28ec3a5ed0e141da 100644 (file)
@@ -362,3 +362,51 @@ hides rule from IE5-Mac \*/
   cursor: pointer;\r
 }\r
 \r
+\r
+/* rails error field stuff */\r
+\r
+.fieldWithErrors {\r
+  padding: 2px;\r
+  background-color: red;\r
+  display: table;\r
+}\r
+\r
+#notice {\r
+  width: 400px;\r
+  border: 2px solid green;\r
+  padding: 7px;\r
+  padding-bottom: 12px;\r
+  margin-bottom: 20px;\r
+  background-color: #f0f0f0;\r
+}\r
+\r
+#errorExplanation {\r
+  width: 400px;\r
+  border: 2px solid red;\r
+  padding: 7px;\r
+  padding-bottom: 12px;\r
+  margin-bottom: 20px;\r
+  background-color: #f0f0f0;\r
+}\r
+\r
+#errorExplanation h2 {\r
+  text-align: left;\r
+  font-weight: bold;\r
+  padding: 5px 5px 5px 15px;\r
+  font-size: 12px;\r
+  margin: -7px;\r
+  background-color: #c00;\r
+  color: #fff;\r
+}\r
+\r
+#errorExplanation p {\r
+  color: #333;\r
+  margin-bottom: 0;\r
+  padding: 5px;\r
+}\r
+\r
+#errorExplanation ul li {\r
+  font-size: 12px;\r
+  list-style: square;\r
+}\r
+\r