Grosse MàJ

This commit is contained in:
olivier
2008-11-25 22:11:16 +01:00
parent 53195fdfcd
commit 3e719157ea
2980 changed files with 343846 additions and 0 deletions

View File

@ -0,0 +1,7 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
# Pick a unique cookie name to distinguish our session data from others'
session :session_key => '_3dossmanno_annuaire_session_id'
end

View File

@ -0,0 +1,31 @@
# This controller handles the login/logout function of the site.
class SessionsController < ApplicationController
# Be sure to include AuthenticationSystem in Application Controller instead
include AuthenticatedSystem
# render new.rhtml
def new
end
def create
self.current_user = User.authenticate(params[:login], params[:password])
if logged_in?
if params[:remember_me] == "1"
self.current_user.remember_me
cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
end
redirect_back_or_default('/')
flash[:notice] = "Logged in successfully"
else
render :action => 'new'
end
end
def destroy
self.current_user.forget_me if logged_in?
cookies.delete :auth_token
reset_session
flash[:notice] = "You have been logged out."
redirect_back_or_default('/')
end
end

View File

@ -0,0 +1,30 @@
class UsersController < ApplicationController
# Be sure to include AuthenticationSystem in Application Controller instead
include AuthenticatedSystem
# render new.rhtml
def new
end
def create
cookies.delete :auth_token
reset_session
@user = User.new(params[:user])
@user.save!
self.current_user = @user
redirect_back_or_default('/')
flash[:notice] = "Thanks for signing up!"
rescue ActiveRecord::RecordInvalid
render :action => 'new'
end
def activate
self.current_user = params[:activation_code].blank? ? :false : User.find_by_activation_code(params[:activation_code])
if logged_in? && !current_user.activated?
current_user.activate
flash[:notice] = "Signup complete!"
end
redirect_back_or_default('/')
end
end

View File

@ -0,0 +1,79 @@
class UtilisateursController < ApplicationController
# GET /utilisateurs
# GET /utilisateurs.xml
def index
@utilisateurs = Utilisateur.find(:all)
respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @utilisateurs.to_xml }
end
end
# GET /utilisateurs/1
# GET /utilisateurs/1.xml
def show
@utilisateur = Utilisateur.find(params[:id])
respond_to do |format|
format.html # show.rhtml
format.xml { render :xml => @utilisateur.to_xml }
end
end
# GET /utilisateurs/new
def new
@utilisateur = Utilisateur.new
end
# GET /utilisateurs/1;edit
def edit
@utilisateur = Utilisateur.find(params[:id])
end
# POST /utilisateurs
# POST /utilisateurs.xml
def create
@utilisateur = Utilisateur.new(params[:utilisateur])
respond_to do |format|
if @utilisateur.save
flash[:notice] = 'Utilisateur was successfully created.'
format.html { redirect_to utilisateur_url(@utilisateur) }
format.xml { head :created, :location => utilisateur_url(@utilisateur) }
else
format.html { render :action => "new" }
format.xml { render :xml => @utilisateur.errors.to_xml }
end
end
end
# PUT /utilisateurs/1
# PUT /utilisateurs/1.xml
def update
@utilisateur = Utilisateur.find(params[:id])
respond_to do |format|
if @utilisateur.update_attributes(params[:utilisateur])
flash[:notice] = 'Utilisateur was successfully updated.'
format.html { redirect_to utilisateur_url(@utilisateur) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @utilisateur.errors.to_xml }
end
end
end
# DELETE /utilisateurs/1
# DELETE /utilisateurs/1.xml
def destroy
@utilisateur = Utilisateur.find(params[:id])
@utilisateur.destroy
respond_to do |format|
format.html { redirect_to utilisateurs_url }
format.xml { head :ok }
end
end
end

View File

@ -0,0 +1,3 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end

View File

@ -0,0 +1,2 @@
module SessionsHelper
end

View File

@ -0,0 +1,2 @@
module UsersHelper
end

View File

@ -0,0 +1,2 @@
module UtilisateursHelper
end

View File

@ -0,0 +1,98 @@
require 'digest/sha1'
class User < ActiveRecord::Base
# Virtual attribute for the unencrypted password
attr_accessor :password
validates_presence_of :login, :email
validates_presence_of :password, :if => :password_required?
validates_presence_of :password_confirmation, :if => :password_required?
validates_length_of :password, :within => 4..40, :if => :password_required?
validates_confirmation_of :password, :if => :password_required?
validates_length_of :login, :within => 3..40
validates_length_of :email, :within => 3..100
validates_uniqueness_of :login, :email, :case_sensitive => false
before_save :encrypt_password
before_create :make_activation_code
# prevents a user from submitting a crafted form that bypasses activation
# anything else you want your user to change should be added here.
attr_accessible :login, :email, :password, :password_confirmation
# Activates the user in the database.
def activate
@activated = true
self.activated_at = Time.now.utc
self.activation_code = nil
save(false)
end
def activated?
# the existence of an activation code means they have not activated yet
activation_code.nil?
end
# Returns true if the user has just been activated.
def recently_activated?
@activated
end
# Authenticates a user by their login name and unencrypted password. Returns the user or nil.
def self.authenticate(login, password)
u = find :first, :conditions => ['login = ? and activated_at IS NOT NULL', login] # need to get the salt
u && u.authenticated?(password) ? u : nil
end
# Encrypts some data with the salt.
def self.encrypt(password, salt)
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
end
# Encrypts the password with the user salt
def encrypt(password)
self.class.encrypt(password, salt)
end
def authenticated?(password)
crypted_password == encrypt(password)
end
def remember_token?
remember_token_expires_at && Time.now.utc < remember_token_expires_at
end
# These create and unset the fields required for remembering users between browser closes
def remember_me
remember_me_for 2.weeks
end
def remember_me_for(time)
remember_me_until time.from_now.utc
end
def remember_me_until(time)
self.remember_token_expires_at = time
self.remember_token = encrypt("#{email}--#{remember_token_expires_at}")
save(false)
end
def forget_me
self.remember_token_expires_at = nil
self.remember_token = nil
save(false)
end
protected
# before filter
def encrypt_password
return if password.blank?
self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--") if new_record?
self.crypted_password = encrypt(password)
end
def password_required?
crypted_password.blank? || !password.blank?
end
def make_activation_code
self.activation_code = Digest::SHA1.hexdigest( Time.now.to_s.split(//).sort_by {rand}.join )
end
end

View File

@ -0,0 +1,24 @@
class UserMailer < ActionMailer::Base
def signup_notification(user)
setup_email(user)
@subject += 'Please activate your new account'
@body[:url] = "http://YOURSITE/activate/#{user.activation_code}"
end
def activation(user)
setup_email(user)
@subject += 'Your account has been activated!'
@body[:url] = "http://YOURSITE/"
end
protected
def setup_email(user)
@recipients = "#{user.email}"
@from = "ADMINEMAIL"
@subject = "[YOURSITE] "
@sent_on = Time.now
@body[:user] = user
end
end

View File

@ -0,0 +1,11 @@
class UserObserver < ActiveRecord::Observer
def after_create(user)
UserMailer.deliver_signup_notification(user)
end
def after_save(user)
UserMailer.deliver_activation(user) if user.recently_activated?
end
end

View File

@ -0,0 +1,2 @@
class Utilisateur < ActiveRecord::Base
end

View File

@ -0,0 +1,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Utilisateurs: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
</body>
</html>

View File

@ -0,0 +1,14 @@
<% form_tag session_path do -%>
<p><label for="login">Login</label><br/>
<%= text_field_tag 'login' %></p>
<p><label for="password">Password</label><br/>
<%= password_field_tag 'password' %></p>
<!-- Uncomment this if you want this functionality
<p><label for="remember_me">Remember me:</label>
<%= check_box_tag 'remember_me' %></p>
-->
<p><%= submit_tag 'Log in' %></p>
<% end -%>

View File

@ -0,0 +1,3 @@
<%= @user.login %>, your account has been activated. You may now start adding your plugins:
<%= @url %>

View File

@ -0,0 +1,8 @@
Your account has been created.
Username: <%= @user.login %>
Password: <%= @user.password %>
Visit this url to activate your account:
<%= @url %>

View File

@ -0,0 +1,16 @@
<%= error_messages_for :user %>
<% form_for :user, :url => users_path do |f| -%>
<p><label for="login">Login</label><br/>
<%= f.text_field :login %></p>
<p><label for="email">Email</label><br/>
<%= f.text_field :email %></p>
<p><label for="password">Password</label><br/>
<%= f.password_field :password %></p>
<p><label for="password_confirmation">Confirm Password</label><br/>
<%= f.password_field :password_confirmation %></p>
<p><%= submit_tag 'Sign up' %></p>
<% end -%>

View File

@ -0,0 +1,62 @@
<h1>Edition utilisateur</h1>
<%= error_messages_for :utilisateur %>
<% form_for(:utilisateur, :url => utilisateur_path(@utilisateur), :html => { :method => :put }) do |f| %>
<p>
<b>Nom</b><br />
<%= f.text_field :nom %>
</p>
<p>
<b>Pr<50>nom</b><br />
<%= f.text_field :prenom %>
</p>
<p>
<b>Classe</b><br />
<%= f.text_field :classe %>
</p>
<p>
<b>Adresse courriel</b><br />
<%= f.text_field :email %>
</p>
<p>
<b>Age</b><br />
<%= f.text_field :age %>
</p>
<p>
<b>Rue</b><br />
<%= f.text_field :rue %>
</p>
<p>
<b>Code postal</b><br />
<%= f.text_field :codePostal %>
</p>
<p>
<b>Ville</b><br />
<%= f.text_field :ville %>
</p>
<p>
<b>Photo</b><br />
<%= f.text_field :photo %>
</p>
<p>
<b>Type</b><br />
<%= f.text_field :type %>
</p>
<p>
<%= submit_tag "Mise <20> jour" %>
</p>
<% end %>
<%= link_to 'Montrer', utilisateur_path(@utilisateur) %> |
<%= link_to 'Retour', utilisateurs_path %>

View File

@ -0,0 +1,38 @@
<h1>Listing utilisateurs</h1>
<table>
<tr>
<th>Nom</th>
<th>Pr<50>nom</th>
<th>Classe</th>
<th>Email</th>
<th>Age</th>
<th>Rue</th>
<th>Code Postal</th>
<th>Ville</th>
<th>Photo</th>
<th>Type</th>
</tr>
<% for utilisateur in @utilisateurs %>
<tr>
<td><%=h utilisateur.nom %></td>
<td><%=h utilisateur.prenom %></td>
<td><%=h utilisateur.classe %></td>
<td><%=h utilisateur.email %></td>
<td><%=h utilisateur.age %></td>
<td><%=h utilisateur.rue %></td>
<td><%=h utilisateur.codePostal %></td>
<td><%=h utilisateur.ville %></td>
<td><%=h utilisateur.photo %></td>
<td><%=h utilisateur.type %></td>
<td><%= link_to 'Montrer', utilisateur_path(utilisateur) %></td>
<td><%= link_to 'Editer', edit_utilisateur_path(utilisateur) %></td>
<td><%= link_to 'Supprimer', utilisateur_path(utilisateur), :confirm => 'Etes vous s<>r ?', :method => :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'Nouvel utilisateur', new_utilisateur_path %>

View File

@ -0,0 +1,61 @@
<h1>New utilisateur</h1>
<%= error_messages_for :utilisateur %>
<% form_for(:utilisateur, :url => utilisateurs_path) do |f| %>
<p>
<b>Nom</b><br />
<%= f.text_field :nom %>
</p>
<p>
<b>Prenom</b><br />
<%= f.text_field :prenom %>
</p>
<p>
<b>Classe</b><br />
<%= f.text_field :classe %>
</p>
<p>
<b>Email</b><br />
<%= f.text_field :email %>
</p>
<p>
<b>Age</b><br />
<%= f.text_field :age %>
</p>
<p>
<b>Rue</b><br />
<%= f.text_field :rue %>
</p>
<p>
<b>Codepostal</b><br />
<%= f.text_field :codePostal %>
</p>
<p>
<b>Ville</b><br />
<%= f.text_field :ville %>
</p>
<p>
<b>Photo</b><br />
<%= f.text_field :photo %>
</p>
<p>
<b>Type</b><br />
<%= f.text_field :type %>
</p>
<p>
<%= submit_tag "Create" %>
</p>
<% end %>
<%= link_to 'Back', utilisateurs_path %>

View File

@ -0,0 +1,53 @@
<p>
<b>Nom:</b>
<%=h @utilisateur.nom %>
</p>
<p>
<b>Prenom:</b>
<%=h @utilisateur.prenom %>
</p>
<p>
<b>Classe:</b>
<%=h @utilisateur.classe %>
</p>
<p>
<b>Email:</b>
<%=h @utilisateur.email %>
</p>
<p>
<b>Age:</b>
<%=h @utilisateur.age %>
</p>
<p>
<b>Rue:</b>
<%=h @utilisateur.rue %>
</p>
<p>
<b>Codepostal:</b>
<%=h @utilisateur.codePostal %>
</p>
<p>
<b>Ville:</b>
<%=h @utilisateur.ville %>
</p>
<p>
<b>Photo:</b>
<%=h @utilisateur.photo %>
</p>
<p>
<b>Type:</b>
<%=h @utilisateur.type %>
</p>
<%= link_to 'Edit', edit_utilisateur_path(@utilisateur) %> |
<%= link_to 'Back', utilisateurs_path %>