setup form finished

This commit is contained in:
Wojciech Todryk 2011-07-23 21:55:26 +02:00
parent 99fcbbb8d0
commit da03add37b
22 changed files with 285 additions and 32 deletions

View file

@ -3,9 +3,7 @@ require 'yaml'
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
protect_from_forgery protect_from_forgery
before_filter :load_defaults,:set_locale,:current_user
before_filter :load_defaults
before_filter :set_locale
protected protected
@ -14,11 +12,31 @@ class ApplicationController < ActionController::Base
end end
def theme_resolver def theme_resolver
@defaults['theme'] if @current_user.nil?
@defaults['theme']
else
@current_user.theme
end
end end
def set_locale def set_locale
I18n.locale = @defaults['locale'] || I18n.default_locale if @current_user.nil?
I18n.locale = @defaults['locale'] || I18n.default_locale
else
I18n.locale = @current_user.locale || I18n.default_locale
end
end
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
def check_current_user
if @current_user.nil?
session["return_to"] = request.fullpath
redirect_to :controller=>"user", :action => "login"
return false
end
end end
end end

View file

@ -1,5 +1,9 @@
class MessagesController < ApplicationController class MessagesController < ApplicationController
def index
end before_filter :check_current_user
theme :theme_resolver
def index
end
end end

View file

@ -1,26 +1,59 @@
class UserController < ApplicationController class UserController < ApplicationController
theme :theme_resolver theme :theme_resolver
layout "simple" layout "simple"
def login def login
end end
def logout def logout
reset_session reset_session
flash[:notice] = t(:user_logged_out) flash[:notice] = t(:user_logged_out)
redirect_to :action => "login" redirect_to :action => "login"
end end
def authenticate def authenticate
redirect_to :action => 'unknown' user = User.find_by_email(params["user"]["email"])
#redirect_to :controller => "messages", :action => "index" if user.nil?
end redirect_to :action => 'unknown'
else
auten = false
if auten == true
def setup else
end flash[:error] = t(:login_failure)
redirect_to :action => 'login'
end
end
end
def unknown def loginfailure
end end
def setup
@user = User.new
@server = Server.new
end
def unknown
end
def create
@user = User.new
@server = Server.new
@user.email = params["user_email"]
@user.first_name = params["user_first_name"]
@user.last_name = params["user_last_name"]
@server.name = params["server_name"]
if @user.valid? and @server.valid?
@user.save
@server.user_id = @user.id
@server.save
flash[:notice] = t(:setup_done)
redirect_to :action => 'login'
else
render "setup"
end
end
end end

View file

@ -1,2 +1,52 @@
module ApplicationHelper module ApplicationHelper
def form_field(object,field,flabel,example)
html = ""
html << "<div class=\"group\">"
if object.errors[field.to_sym]
html << "<div class=\"fieldWithErrors\">"
end
html << "<label class=\"label\">"
if flabel.nil?
html << t(field.to_sym)
else
html << t(flabel.to_sym)
end
html << "</label>"
if object.errors[field.to_sym]
html << "<span class=\"error\"> "
html << object.errors[field.to_sym].to_s
html << "</span>"
html << "</div>"
end
html << "<input name=\""
html << object.class.name.downcase+"_"+field
html << "\" type=\"text\" class=\"text_field\" value=\""
value = object.instance_eval(field) || ""
html << value
html << "\"/>"
html << "<span class=\"description\">"
html << t(:example)
html << ": "
html << example
html << "</span>"
html << "</div>"
end
def form_button(text)
html = ""
html << "<div class=\"group navform wat-cf\">"
html << "<button class=\"button\" type=\"submit\">"
html << "<img src=\""
html << current_theme_image_path('tick.png')
html << "\" alt=\""
html << text
html << "\" />"
html << t(text.to_sym)
html << "</button></div>"
end
end end

4
app/models/server.rb Normal file
View file

@ -0,0 +1,4 @@
class Server < ActiveRecord::Base
validates_presence_of :name
belongs_to :user
end

6
app/models/user.rb Normal file
View file

@ -0,0 +1,6 @@
class User < ActiveRecord::Base
validates_presence_of :email, :on => :create
validates_presence_of :first_name,:last_name
validates_uniqueness_of :email
has_many :servers, :dependent => :destroy
end

View file

@ -71,3 +71,8 @@ en:
unknown_user_flash: Your email identifier was not found in database unknown_user_flash: Your email identifier was not found in database
unknown_user_login: Go to login page and try to login once more. unknown_user_login: Go to login page and try to login once more.
unknown_user_setup: Go to setup page and do the setup of Your mail account. unknown_user_setup: Go to setup page and do the setup of Your mail account.
setup_title: Setup
example: example
server_name: Server name
setup_done: Setup done. Please log in
login_failure: Login failure. Bad email or password

View file

@ -4,6 +4,7 @@ Mailr::Application.routes.draw do
get "messages/index" get "messages/index"
get "user/logout" get "user/logout"
post "user/authenticate" post "user/authenticate"
post "user/create"
get "user/login" get "user/login"
get "user/setup" get "user/setup"
get "user/unknown" get "user/unknown"

View file

@ -0,0 +1,15 @@
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :email
t.string :first_name
t.string :last_name
t.timestamps
end
end
def self.down
drop_table :users
end
end

View file

@ -0,0 +1,14 @@
class CreateServers < ActiveRecord::Migration
def self.up
create_table :servers do |t|
t.string :name
t.string :port
t.references :user
t.timestamps
end
end
def self.down
drop_table :servers
end
end

31
db/schema.rb Normal file
View file

@ -0,0 +1,31 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110723153214) do
create_table "servers", :force => true do |t|
t.string "name"
t.string "port"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "users", :force => true do |t|
t.string "email"
t.string "first_name"
t.string "last_name"
t.datetime "created_at"
t.datetime "updated_at"
end
end

9
test/fixtures/servers.yml vendored Normal file
View file

@ -0,0 +1,9 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
one:
name: MyString
port: MyString
two:
name: MyString
port: MyString

11
test/fixtures/users.yml vendored Normal file
View file

@ -0,0 +1,11 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
one:
email: MyString
first_name: MyString
last_name: MyString
two:
email: MyString
first_name: MyString
last_name: MyString

8
test/unit/server_test.rb Normal file
View file

@ -0,0 +1,8 @@
require 'test_helper'
class ServerTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end

8
test/unit/user_test.rb Normal file
View file

@ -0,0 +1,8 @@
require 'test_helper'
class UserTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 B

View file

@ -333,7 +333,7 @@ ul.list li .item .avatar {
#box { #box {
width: 500px; width: 500px;
margin: 50px auto; margin: 20px auto;
} }
#box .block { #box .block {

View file

@ -340,7 +340,7 @@ ul.list li .item .avatar {
-webkit-border-bottom-right-radius: 4px; -webkit-border-bottom-right-radius: 4px;
} }
#block-login #logo { .block #logo {
height: 65; height: 65;
background-color: #EFF3E4; background-color: #EFF3E4;
} }
@ -360,4 +360,9 @@ input,select {
margin: 5px 0 0; margin: 5px 0 0;
} }
#footer {
text-align: center;
color: grey;
}

View file

@ -3,11 +3,14 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<title><%=t(:mailr) %></title> <title><%=t(:mailr) %> -
<%= yield :title %>
</title>
<%=stylesheet_link_tag current_theme_stylesheet_path('base') %> <%=stylesheet_link_tag current_theme_stylesheet_path('base') %>
<%=stylesheet_link_tag current_theme_stylesheet_path('style') %> <%=stylesheet_link_tag current_theme_stylesheet_path('style') %>
</head> </head>
<body> <body>
<%= yield %> <%= yield %>
<div id="footer"><a href="<%= t(:site_link) %>">Mailr</a> - open source web mail client</div>
</body> </body>
</html> </html>

View file

@ -1,6 +1,10 @@
<% content_for :title do %>
<%= t(:please_login) %>
<% end %>
<div id="box"> <div id="box">
<div class="block" id="block-login"> <div class="block">
<div id="logo"><a href="<%= t(:site_link) %>"><img src="<%= current_theme_image_path('logo_small.png')%>" alt="Mailr"/></a> <div id="logo"><a href="/"><img src="<%= current_theme_image_path('logo_small.png')%>" alt="Mailr"/></a>
</div> </div>
<h2><%= t(:please_login) %></h2> <h2><%= t(:please_login) %></h2>
<div class="content login"> <div class="content login">
@ -17,7 +21,7 @@
<label class="label right"><%= t(:email) %></label> <label class="label right"><%= t(:email) %></label>
</div> </div>
<div class="right"> <div class="right">
<%= text_field "login_user", "email" %> <%= text_field "user", "email" %>
</div> </div>
</div> </div>
<div class="group wat-cf"> <div class="group wat-cf">
@ -25,7 +29,7 @@
<label class="label right"><%= t(:password) %></label> <label class="label right"><%= t(:password) %></label>
</div> </div>
<div class="right"> <div class="right">
<%= password_field "login_user", "password" %></td> <%= password_field "user", "password" %></td>
</div> </div>
</div> </div>
<div class="group navform wat-cf"> <div class="group navform wat-cf">

View file

@ -0,0 +1,20 @@
<% content_for :title do %>
<%= t(:setup_title) %>
<% end %>
<div id="box">
<div class="block">
<div id="logo"><a href="/"><img src="<%= current_theme_image_path('logo_small.png')%>" alt="Mailr"/></a>
</div>
<h2><%= t(:setup_title) %></h2>
<div class="content">
<form action="<%=url_for(:controller => 'user', :action => 'create')%>" method="post" class="form">
<%= raw form_field(@user,"email",nil,"joe.doe@domain.domain") %>
<%= raw form_field(@user,"first_name",nil,"Joe") %>
<%= raw form_field(@user,"last_name",nil,"Doe") %>
<%= raw form_field(@server,"name","server_name","domain.domain") %>
<%= raw form_button("send") %>
</form>
</div>
</div>
</div>

View file

@ -1,6 +1,10 @@
<% content_for :title do %>
<%= t(:unknown_user_title) %>
<% end %>
<div id="box"> <div id="box">
<div class="block" id="block-login"> <div class="block" id="block-login">
<div id="logo"><a href="<%= t(:site_link) %>"><img src="<%= current_theme_image_path('logo_small.png')%>" alt="Mailr"/></a> <div id="logo"><a href="/"><img src="<%= current_theme_image_path('logo_small.png')%>" alt="Mailr"/></a>
</div> </div>
<h2><%= t(:unknown_user_title) %></h2> <h2><%= t(:unknown_user_title) %></h2>
<div class="content"> <div class="content">