setup form finished

from_scratch
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
protect_from_forgery
before_filter :load_defaults
before_filter :set_locale
before_filter :load_defaults,:set_locale,:current_user
protected
@ -14,11 +12,31 @@ class ApplicationController < ActionController::Base
end
def theme_resolver
@defaults['theme']
if @current_user.nil?
@defaults['theme']
else
@current_user.theme
end
end
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

View File

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

View File

@ -1,26 +1,59 @@
class UserController < ApplicationController
theme :theme_resolver
layout "simple"
theme :theme_resolver
layout "simple"
def login
end
def login
end
def logout
reset_session
flash[:notice] = t(:user_logged_out)
redirect_to :action => "login"
end
def logout
reset_session
flash[:notice] = t(:user_logged_out)
redirect_to :action => "login"
end
def authenticate
redirect_to :action => 'unknown'
#redirect_to :controller => "messages", :action => "index"
end
def authenticate
user = User.find_by_email(params["user"]["email"])
if user.nil?
redirect_to :action => 'unknown'
else
auten = false
if auten == true
def setup
end
else
flash[:error] = t(:login_failure)
redirect_to :action => 'login'
end
end
end
def unknown
end
def loginfailure
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

View File

@ -1,2 +1,52 @@
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

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_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.
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 "user/logout"
post "user/authenticate"
post "user/create"
get "user/login"
get "user/setup"
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 {
width: 500px;
margin: 50px auto;
margin: 20px auto;
}
#box .block {

View File

@ -340,7 +340,7 @@ ul.list li .item .avatar {
-webkit-border-bottom-right-radius: 4px;
}
#block-login #logo {
.block #logo {
height: 65;
background-color: #EFF3E4;
}
@ -360,4 +360,9 @@ input,select {
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">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<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('style') %>
</head>
<body>
<%= yield %>
<div id="footer"><a href="<%= t(:site_link) %>">Mailr</a> - open source web mail client</div>
</body>
</html>

View File

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