internal controller added
This commit is contained in:
parent
86e1817e29
commit
f81c1d69c5
1
Gemfile
1
Gemfile
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
12
app/controllers/internal_controller.rb
Normal file
12
app/controllers/internal_controller.rb
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
if session["return_to"]
|
||||
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"
|
||||
redirect_to :controller=> "messages", :action=>"index"
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
flash[:error] = t(:login_failure)
|
||||
redirect_to :action => 'login'
|
||||
|
|
2
app/helpers/internal_helper.rb
Normal file
2
app/helpers/internal_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module InternalHelper
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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#
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
48
lib/imap_utils.rb
Normal 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
|
9
test/functional/internal_controller_test.rb
Normal file
9
test/functional/internal_controller_test.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
require 'test_helper'
|
||||
|
||||
class InternalControllerTest < ActionController::TestCase
|
||||
test "should get error" do
|
||||
get :error
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
end
|
4
test/unit/helpers/internal_helper_test.rb
Normal file
4
test/unit/helpers/internal_helper_test.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
require 'test_helper'
|
||||
|
||||
class InternalHelperTest < ActionView::TestCase
|
||||
end
|
14
themes/olive/views/internal/error.html.erb
Normal file
14
themes/olive/views/internal/error.html.erb
Normal 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>
|
Loading…
Reference in a new issue