more rails updates

This commit is contained in:
Steve Coast 2006-08-01 17:50:10 +00:00
parent 88297a682c
commit 37bd2971b4
9 changed files with 123 additions and 15 deletions

View 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

View 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

View file

@ -1,4 +1,6 @@
class Node < ActiveRecord::Base
set_table_name 'current_nodes'
belongs_to :user
end

View 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

View file

@ -11,6 +11,10 @@
<body>
<div id="content">
<% if @flash[:notice] %>
<div id="notice"><%= @flash[:notice] %></div>
<% end %>
<%= @content_for_layout %>
</div>

View file

@ -0,0 +1 @@

View 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>

View file

@ -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;
}