internal controller added

This commit is contained in:
Wojciech Todryk 2011-07-24 22:22:13 +02:00
parent 86e1817e29
commit f81c1d69c5
15 changed files with 140 additions and 7 deletions

View file

@ -10,6 +10,7 @@ gem 'arel'
gem 'mysql2' , '0.2.7'
gem 'will_paginate'
gem 'themes_for_rails'
gem "ezcrypto", "~> 0.7.2"
#gem 'tmail'
# Use unicorn as the web server

View file

@ -30,6 +30,7 @@ GEM
arel (2.0.10)
builder (2.1.2)
erubis (2.7.0)
ezcrypto (0.7.2)
i18n (0.5.0)
mail (2.2.19)
activesupport (>= 2.3.6)
@ -72,6 +73,7 @@ PLATFORMS
DEPENDENCIES
arel
ezcrypto (~> 0.7.2)
mysql2 (= 0.2.7)
rails (= 3.0.7)
themes_for_rails

View file

@ -15,7 +15,7 @@ class ApplicationController < ActionController::Base
if @current_user.nil?
$defaults['theme']
else
@current_user.prefs.theme
@current_user.prefs.theme || $defaults['theme']
end
end

View file

@ -0,0 +1,12 @@
class InternalController < ApplicationController
theme :theme_resolver
layout "simple"
def error
@title = t(:general_error)
@error = params[:error] || t(:unspecified_error)
logger.error @error
end
end

View file

@ -1,10 +1,14 @@
require 'imap_utils'
class MessagesController < ApplicationController
before_filter :check_current_user
include ImapUtils
before_filter :check_current_user, :info
theme :theme_resolver
def index
logger.info "YYYYYYYYYYYYY #{@m.inspect}"
end
end

View file

@ -13,19 +13,23 @@ class UserController < ApplicationController
end
def authenticate
user = User.find_by_email(params["user"]["email"])
user = User.find_by_email(params[:user][:email])
if user.nil?
redirect_to :action => 'unknown'
else
auten = true
if auten == true
session[:user_id] = user.id
user.set_cached_password(session,params[:user][:password])
if session["return_to"]
redirect_to(session["return_to"])
session["return_to"] = nil
else
redirect_to :controller=> "messages", :action=>"index"
end
else
flash[:error] = t(:login_failure)
redirect_to :action => 'login'

View file

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

View file

@ -1,7 +1,31 @@
require 'ezcrypto'
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
has_one :prefs, :dependent => :destroy
def set_cached_password(session,password)
if $defaults['session_encryption']
session[:session_salt] = generate_salt
session[:user_password] = EzCrypto::Key.encrypt_with_password($defaults['session_password'], session[:session_salt], password)
else
session[:user_password] = password
end
end
def get_cached_password(session)
if $defaults['session_encryption']
EzCrypto::Key.decrypt_with_password($defaults['session_password'], session[:session_salt], session[:user_password])
else
session[:user_password]
end
end
def generate_salt
(0...8).map{65.+(rand(25)).chr}.join
end
end

View file

@ -2,3 +2,7 @@ theme: olive
locale: en
msgs_per_page: 20
msg_send_type: html
imap_debug: true
session_encryption: true
session_password: asDD3s2@sAdc983#

View file

@ -76,3 +76,5 @@ en:
server_name: Server name
setup_done: Setup done. Please log in
login_failure: Login failure. Bad email or password
general_error: General error
unspecified_error: Unspecified error occured

View file

@ -1,5 +1,8 @@
Mailr::Application.routes.draw do
get "internal/error"
post "internal/error"
root :to => "messages#index"
get "messages/index"
get "user/logout"

48
lib/imap_utils.rb Normal file
View file

@ -0,0 +1,48 @@
require 'net/imap'
module ImapUtils
class IMAPMailbox
#
# attr_reader :connected
# attr_accessor :selected_mailbox
# cattr_accessor :logger
#
def initialize(logger)
# @selected_mailbox = ''
# @folders = {}
# @connected = false
@logger = logger
@logger.info "XXXXXXXXXX i am in"
end
#
end
def info
@m = IMAPMailbox.new(logger)
logger.info "XXXXXXXXXXXXX"
logger.info @m.inspect
end
#
#def load_imap_session
# begin
# @mailbox = IMAPMailbox.new(self.logger)
## uname = (get_mail_prefs.check_external_mail == 1 ? user.email : user.local_email)
## upass = get_upass
## @mailbox.connect(uname, upass)
## load_folders
# rescue Exception => ex
# render :controller => "internal", :action => "error" , :error => ex.inspect
# end
#end
# def close_imap_session
# return if @mailbox.nil? or not(@mailbox.connected)
# @mailbox.disconnect
# @mailbox = nil
# end
end

View file

@ -0,0 +1,9 @@
require 'test_helper'
class InternalControllerTest < ActionController::TestCase
test "should get error" do
get :error
assert_response :success
end
end

View file

@ -0,0 +1,4 @@
require 'test_helper'
class InternalHelperTest < ActionView::TestCase
end

View file

@ -0,0 +1,14 @@
<% content_for :title do %>
<%= @title %>
<% end %>
<div id="box">
<div class="block block-login">
<div id="logo"><a href="/"><img src="<%= current_theme_image_path('logo_small.png')%>" alt="Mailr"/></a>
</div>
<h2><%= @title %></h2>
<div class="content">
<div class="flash"><div class="message error"><p><%= @description %></p></div></div>
</div>
</div>
</div>