From 37bd2971b49da9364fe5dd25415e97e38b34abd7 Mon Sep 17 00:00:00 2001 From: Steve Coast Date: Tue, 1 Aug 2006 17:50:10 +0000 Subject: [PATCH 1/1] more rails updates --- app/controllers/node_controller.rb | 7 +++ app/controllers/user_controller.rb | 27 ++++++++++-- app/models/node.rb | 2 + app/models/user.rb | 47 ++++++++++++++------ app/views/layouts/user.rhtml | 4 ++ app/views/user/confirm.rhtml | 1 + app/views/user/new.rhtml | 2 + app/views/user/{signup.rhtml => save.rhtml} | 0 public/stylesheets/site.css | 48 +++++++++++++++++++++ 9 files changed, 123 insertions(+), 15 deletions(-) create mode 100644 app/views/user/confirm.rhtml rename app/views/user/{signup.rhtml => save.rhtml} (100%) diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb index cafc0f00f..6092ddd9d 100644 --- a/app/controllers/node_controller.rb +++ b/app/controllers/node_controller.rb @@ -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 diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 7a0c8b3d7..b982a93c9 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -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 diff --git a/app/models/node.rb b/app/models/node.rb index 914e90b7e..d1bedd03c 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -1,4 +1,6 @@ class Node < ActiveRecord::Base set_table_name 'current_nodes' + belongs_to :user + end diff --git a/app/models/user.rb b/app/models/user.rb index 72752078e..1a1279042 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/layouts/user.rhtml b/app/views/layouts/user.rhtml index 3d8287fcd..cee649145 100644 --- a/app/views/layouts/user.rhtml +++ b/app/views/layouts/user.rhtml @@ -11,6 +11,10 @@
+<% if @flash[:notice] %> +
<%= @flash[:notice] %>
+<% end %> + <%= @content_for_layout %>
diff --git a/app/views/user/confirm.rhtml b/app/views/user/confirm.rhtml new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/app/views/user/confirm.rhtml @@ -0,0 +1 @@ + diff --git a/app/views/user/new.rhtml b/app/views/user/new.rhtml index 00ab2c7d8..bc237f0a9 100644 --- a/app/views/user/new.rhtml +++ b/app/views/user/new.rhtml @@ -3,6 +3,8 @@ Fill in the form and we'll send you a quick email to activate your account.
< 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 this Creative Commons license.

+<%= error_messages_for 'user' %> + <%= start_form_tag :action => 'save' %> diff --git a/app/views/user/signup.rhtml b/app/views/user/save.rhtml similarity index 100% rename from app/views/user/signup.rhtml rename to app/views/user/save.rhtml diff --git a/public/stylesheets/site.css b/public/stylesheets/site.css index 0dc7eaf18..9b29cd806 100644 --- a/public/stylesheets/site.css +++ b/public/stylesheets/site.css @@ -362,3 +362,51 @@ hides rule from IE5-Mac \*/ cursor: pointer; } + +/* rails error field stuff */ + +.fieldWithErrors { + padding: 2px; + background-color: red; + display: table; +} + +#notice { + width: 400px; + border: 2px solid green; + padding: 7px; + padding-bottom: 12px; + margin-bottom: 20px; + background-color: #f0f0f0; +} + +#errorExplanation { + width: 400px; + border: 2px solid red; + padding: 7px; + padding-bottom: 12px; + margin-bottom: 20px; + background-color: #f0f0f0; +} + +#errorExplanation h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + background-color: #c00; + color: #fff; +} + +#errorExplanation p { + color: #333; + margin-bottom: 0; + padding: 5px; +} + +#errorExplanation ul li { + font-size: 12px; + list-style: square; +} + -- 2.43.2
email address:<%= text_field('user', 'email',{:size => 50, :maxlength => 255}) %>