Refactoring of invitations.

This commit is contained in:
Benjamin Meichsner 2009-02-02 00:09:50 +01:00
parent d75c206db5
commit aa47a24fda
3 changed files with 41 additions and 35 deletions

View file

@ -102,31 +102,27 @@ class LoginController < ApplicationController
def invite def invite
@invite = Invite.find_by_token(params[:id]) @invite = Invite.find_by_token(params[:id])
if (@invite.nil? || @invite.expires_at < Time.now) if (@invite.nil? || @invite.expires_at < Time.now)
flash[:error] = _("Your invitation is invalid or has expired, sorry!") flash[:error] = "Deine Einladung ist nicht (mehr) gültig."
render :action => 'login' render :action => 'login'
elsif @invite.group.nil? elsif @invite.group.nil?
flash[:error] = _("The group you are invited to join doesn't exist any more!") flash[:error] = "Die Gruppe, in die Du eingeladen wurdest, existiert leider nicht mehr."
render :action => 'login' render :action => 'login'
elsif (request.post?) elsif (request.post?)
User.transaction do User.transaction do
@user = User.new(params[:user]) @user = User.new(params[:user])
@user.email = @invite.email @user.email = @invite.email
@user.set_password({:required => true}, params[:user][:password], params[:user][:password_confirmation]) if @user.save
if (@user.errors.empty? && @user.save)
Membership.new(:user => @user, :group => @invite.group).save! Membership.new(:user => @user, :group => @invite.group).save!
for setting in User::setting_keys.keys
@user.settings[setting] = (params[:user][:settings] && params[:user][:settings][setting] == '1' ? '1' : nil)
end
@invite.destroy @invite.destroy
flash[:notice] = _("Congratulations, your account has been created successfully. You can log in now.") flash[:notice] = "Herzlichen Glückwunsch, Dein Account wurde erstellt. Du kannst Dich nun einloggen."
render(:action => 'login') render :action => 'login'
end end
end end
else else
@user = User.new(:email => @invite.email) @user = User.new(:email => @invite.email)
end end
rescue rescue
flash[:error] = _("An error has occured. Please try again.") flash[:error] = "Ein Fehler ist aufgetreten. Bitte erneut versuchen."
end end
end end

View file

@ -1,47 +1,54 @@
%h1=_ 'Invitation' - title "Einladung in die #{APP_CONFIG[:name]}"
%p %p
=_ 'You are invited to join:' Du bist eingeladen worden in der Foodcoop
%b= @invite.group.name %b= @invite.group.name
%p=_ 'If you accept the invitation and want to join the foodcoop please fill out the form.' mitzumachen.
%p
Wenn Du mitmachen möchtest, dann fülle bitte dieses Formular aus.
%p
Deine Daten werden selbstverständlich nicht an Dritte, aus was auch immer für
Gründen, weitergeben. Du kannst auch entscheiden, wieviel deiner persönlichen
Daten für alle einsehbar sein sollen. 'Alle' bedeutet hier alle Foodcoop-Mitglieder.
Die Administratoren haben aber jederzeit Zugriff auf deine Daten.
.edit_form{:style => "width:25em"} .edit_form{:style => "width:25em"}
- form_for(:user, @user) do |u| - form_for @user, :url => {:action => 'invite'} do |form|
- if flash[:error] - if flash[:error]
%p= flash[:error] %p= flash[:error]
= error_messages_for('user') = form.error_messages
%p %p
%label{:for => 'nick'}=_ 'Nickname (for log in)' Benutzerinnenname (für das Anmelden in der Foodsoft)
%br/ %br/
= u.text_field 'nick', :maxlength => 25 = form.text_field :nick, :maxlength => 25
%p %p
%label{:for => 'first_name'}=_ 'First name' Vorname
%br/ %br/
= u.text_field 'first_name', :maxlength => 50, :size => 25 = form.text_field :first_name, :maxlength => 50, :size => 25
%p %p
%label{:for => 'last_name'}=_ 'Last name' Nachname
%br/ %br/
= u.text_field 'last_name' = form.text_field :last_name
%p %p
%label{:for => 'phone'}=_ 'Phone' Telefon
%br/ %br/
= u.text_field 'phone' = form.text_field :phone
%p %p
%label{:for => 'address'}=_ 'Address' Adresse
%br/ %br/
= u.text_field 'address' = form.text_field :address
%p %p
%label{:for => 'password'}=_ 'Password' Passwort
%br/ %br/
= password_field_tag 'user[password]' = form.password_field :password
%p %p
%label{:for => 'password_confirmation'}=_ 'Passwort confirmation' bitte Passwort wiederholen
%br/ %br/
= password_field_tag 'user[password_confirmation]' = form.password_field :password_confirmation
%h3=_ 'Settings' %h3 Einstellungen
- for setting in User::setting_keys.keys - for setting in User::setting_keys.keys
%p %p
= check_box_tag "user[settings][#{setting}]", '1', @user.settings[setting] == '1' || @user.settings_default(setting) = check_box_tag "user[setting_attributes][#{setting}]", '1', @user.settings[setting] == '1' || @user.settings_default(setting)
%label{:for => "user[settings][#{setting}]"}= User::setting_keys[setting] %label{:for => "user[setting_attributes][#{setting}]"}= User::setting_keys[setting]
= submit_tag _('Send') = submit_tag "Absenden"
= javascript_tag("$('user_login').focus()") = javascript_tag("$('user_nick').focus()")

View file

@ -126,3 +126,6 @@ de:
article: article:
price: Nettopreis price: Nettopreis
gross_price: Bruttopreis gross_price: Bruttopreis
user:
password: Passwort
first_name: Vorname