diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0ad5869..004d67d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 0a33b1f..3ddfcfb 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -1,5 +1,9 @@ class MessagesController < ApplicationController - def index - end + + before_filter :check_current_user + theme :theme_resolver + + def index + end end diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index e70a6b0..a4cfe5b 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..8db6bf8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,52 @@ module ApplicationHelper + +def form_field(object,field,flabel,example) + + html = "" + html << "
" + if object.errors[field.to_sym] + html << "
" + + end + html << "" + if object.errors[field.to_sym] + html << " " + html << object.errors[field.to_sym].to_s + html << "" + html << "
" + end + html << "" + html << "" + html << t(:example) + html << ": " + html << example + html << "" + html << "
" + +end + +def form_button(text) + html = "" + html << "
" + html << "
" +end + end diff --git a/app/models/server.rb b/app/models/server.rb new file mode 100644 index 0000000..3897d85 --- /dev/null +++ b/app/models/server.rb @@ -0,0 +1,4 @@ +class Server < ActiveRecord::Base + validates_presence_of :name + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..87710b9 --- /dev/null +++ b/app/models/user.rb @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 376c0d1..2f7e42c 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 8e2963d..660dcb6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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" diff --git a/db/migrate/20110723115402_create_users.rb b/db/migrate/20110723115402_create_users.rb new file mode 100644 index 0000000..2232901 --- /dev/null +++ b/db/migrate/20110723115402_create_users.rb @@ -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 diff --git a/db/migrate/20110723153214_create_servers.rb b/db/migrate/20110723153214_create_servers.rb new file mode 100644 index 0000000..e69c4aa --- /dev/null +++ b/db/migrate/20110723153214_create_servers.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..3c49415 --- /dev/null +++ b/db/schema.rb @@ -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 diff --git a/test/fixtures/servers.yml b/test/fixtures/servers.yml new file mode 100644 index 0000000..f44a2a8 --- /dev/null +++ b/test/fixtures/servers.yml @@ -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 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000..7060ff2 --- /dev/null +++ b/test/fixtures/users.yml @@ -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 diff --git a/test/unit/server_test.rb b/test/unit/server_test.rb new file mode 100644 index 0000000..2e90285 --- /dev/null +++ b/test/unit/server_test.rb @@ -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 diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb new file mode 100644 index 0000000..a64d2d3 --- /dev/null +++ b/test/unit/user_test.rb @@ -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 diff --git a/themes/olive/images/tick.png b/themes/olive/images/tick.png new file mode 100644 index 0000000..a9925a0 Binary files /dev/null and b/themes/olive/images/tick.png differ diff --git a/themes/olive/stylesheets/base.css b/themes/olive/stylesheets/base.css index 1252312..4a0707d 100755 --- a/themes/olive/stylesheets/base.css +++ b/themes/olive/stylesheets/base.css @@ -333,7 +333,7 @@ ul.list li .item .avatar { #box { width: 500px; - margin: 50px auto; + margin: 20px auto; } #box .block { diff --git a/themes/olive/stylesheets/style.css b/themes/olive/stylesheets/style.css index f0a3f49..f6365a2 100755 --- a/themes/olive/stylesheets/style.css +++ b/themes/olive/stylesheets/style.css @@ -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; + } + diff --git a/themes/olive/views/layouts/simple.html.erb b/themes/olive/views/layouts/simple.html.erb index 142ede7..9f3c7bc 100755 --- a/themes/olive/views/layouts/simple.html.erb +++ b/themes/olive/views/layouts/simple.html.erb @@ -3,11 +3,14 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - <%=t(:mailr) %> + <%=t(:mailr) %> - + <%= yield :title %> + <%=stylesheet_link_tag current_theme_stylesheet_path('base') %> <%=stylesheet_link_tag current_theme_stylesheet_path('style') %> <%= yield %> + diff --git a/themes/olive/views/user/login.html.erb b/themes/olive/views/user/login.html.erb index 4ff69b7..b28867c 100755 --- a/themes/olive/views/user/login.html.erb +++ b/themes/olive/views/user/login.html.erb @@ -1,6 +1,10 @@ +<% content_for :title do %> + <%= t(:please_login) %> +<% end %> +
-
-