diff --git a/.gitignore b/.gitignore index 99331fa..8ee726b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ /Gemfile.lock app/views/frontend +/public/uploads/* diff --git a/Gemfile b/Gemfile index 2f3e68e..19c41e5 100644 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,12 @@ gem 'nokogiri' #database gem 'mongoid', github: "mongoid/mongoid" +#file uploading and carrierwave +gem "mini_magick", github: 'minimagick/minimagick' +gem 'carrierwave' +gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid' +gem 'mongoid-grid_fs', github: 'ahoward/mongoid-grid_fs' + #built in modules eval(File.read(File.dirname(__FILE__) + '/built_in_extensions.rb')) #modules installed from the store diff --git a/app/assets/stylesheets/sign_up.css b/app/assets/stylesheets/sign_up.css new file mode 100644 index 0000000..d51deb2 --- /dev/null +++ b/app/assets/stylesheets/sign_up.css @@ -0,0 +1,100 @@ +.sign-up{ + margin: 150px auto 0; + position: relative; + /*text-align: center;*/ + width: 600px; +} +.sign-up.facebook-form{ + text-align: center; +} +.sign-up .form{ + background-color: #FFFFFF; + box-shadow: 0 10px 20px #CBCBCB; + margin-bottom: 20px; + padding: 15px; +} + +.sign-up .login-logo{ + border-bottom: 1px solid #EDEDED; + margin: 0; + padding-bottom: 15px; +} + +.sign-up .option-block{ + margin-top: 15px; +} +.sign-up .or{ + margin-top: 15px; + margin-bottom: 15px; +} +.sign-up .or span{ + margin-left: 5px; + margin-right: 5px; +} + +.sign-up .or .left{ + margin-top: 10px; + margin-left: 60px; + width: 160px; + float: left; +} +.sign-up .or .right{ + margin-top: 10px; + margin-right: 60px; + width: 160px; + float: right; +} +.sign-up .facebook:hover{ + opacity: 0.8; +} + +.sign-up .role-label{ + display: inline; + margin-left: 3px; + margin-right: 10px; +} + +.sign-up .notify{ + font-size: 15px; +} + +.notify.alert{ + padding: 5px 10px 5px 3px; +} + +.notify .icon-ok{ + color: green; + margin-right: 3px; + margin-left: 3px; +} + +.notify .icon-remove{ + color: red; + margin-right: 3px; + margin-left: 3px; +} + +.sign-up input[type=checkbox]{ + margin-top: 0; +} + +.sign-up .error{ + border-color: #E9322D; + box-shadow: 0 0 6px #F8B987; + color: #B94A48; +} + +.line{ + border-bottom: 1px solid #EDEDED; +} + +.links{ + text-align: left; +} + +.loader{ + width:100px; + margin-left: 3px; +} + + diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7f3b7da..592a509 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,5 @@ class UsersController < ApplicationController + layout "authentication" def new @user = User.new end diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000..a4e94c5 --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,11 @@ +class Category + include Mongoid::Document + include Mongoid::Timestamps + + field :disable, type: Boolean, default: false + field :title, localize: true + + belongs_to :module_app + + scope :enabled, ->{ where(:disable.in => [false, nil, ''])} +end diff --git a/app/models/module_app.rb b/app/models/module_app.rb index e25499c..5bcb83e 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -5,6 +5,8 @@ class ModuleApp field :title, type: String field :key, type: String field :sidebar_order,type: Integer,default: 0 + + has_many :categories, dependent: :destroy, :autosave => true def get_registration OrbitApp::Module::Registration.find_by_key(key) diff --git a/app/models/user.rb b/app/models/user.rb index 7ccce77..d999006 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,4 @@ +#this class handles user login and password. User has the attributes user name, email and password which he / she can choose class User include Mongoid::Document include Mongoid::Timestamps diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb new file mode 100644 index 0000000..1b427d7 --- /dev/null +++ b/app/uploaders/image_uploader.rb @@ -0,0 +1,54 @@ +# encoding: utf-8 +require 'carrierwave/processing/mime_types' + +class ImageUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + # include CarrierWave::MiniMagick + include CarrierWave::MiniMagick + include CarrierWave::MimeTypes + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process :scale => [200, 300] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + version :thumb do + process :resize_to_fit => [200, 200] + end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + def extension_white_list + %w(jpg jpeg gif png) + end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end diff --git a/app/views/layouts/authentication.html.erb b/app/views/layouts/authentication.html.erb new file mode 100644 index 0000000..161bd59 --- /dev/null +++ b/app/views/layouts/authentication.html.erb @@ -0,0 +1,29 @@ + + + + + RulingOrbit | <%= current_site.title %> + + <%= render 'shared/meta' %> + <%= render 'shared/google_font' %> + <%= stylesheet_link_tag "basic/global" %> + <%= stylesheet_link_tag "basic" %> + <%= stylesheet_link_tag "sign_up" %> + + <%= render 'shared/ie_html5_fix' %> + <%= javascript_include_tag "basic" %> + <%= yield :page_specific_css %> + <%= yield :page_specific_javascript %> + + + <%= csrf_meta_tag %> + + + <%= render 'layouts/orbit_bar_backend' %> + <%= yield %> + + diff --git a/app/views/shared/_authentication_links.html.erb b/app/views/shared/_authentication_links.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/users/create.html.erb b/app/views/users/create.html.erb deleted file mode 100644 index 48ea02e..0000000 --- a/app/views/users/create.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Users#create

-

Find me in app/views/users/create.html.erb

diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 3b5b874..b681b21 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,3 +1,64 @@ +
+
+ + <% flash.each do |key, msg| %> + <%= content_tag :p, msg, :class => [key, "alert alert-error in fade"] %> + <% end %> + +
+ +
+
+ + <%= form_for @user, :html => {:class => 'content form-horizontal'} do |f| %> + +
+ +
+ <%= f.text_field :user_name, :placeholder => t("users.user_id"), :id=>"user_id",:class=>"availibility" %> + + Not Available + Available +
+
+
+ +
+ <%= f.email_field :email, :placeholder => t("users.email"), :id=>"user_email", :class=>"availibility" %> + + Not Available + Available +
+
+ +
+ +
+ <%= f.password_field :password, :placeholder => t(:dots), :id=>"user_password" %> +
+
+
+ +
+ <%= f.password_field :password, :placeholder => t(:dots), :id=>"confirm_user_password" %> +
+
+

+
+ <%= f.submit t(:register), :class => 'btn btn-primary' %> +
+ + <% end %> + +
+
+
+ +
+
+ + \ No newline at end of file diff --git a/built_in_extensions.rb b/built_in_extensions.rb index 0861943..c91f1e7 100644 --- a/built_in_extensions.rb +++ b/built_in_extensions.rb @@ -1 +1,2 @@ gem 'announcement', git: 'git@gitlab.tp.rulingcom.com:saurabh/announcement-test.git' +gem 'ad_banner', git: 'git@gitlab.tp.rulingcom.com:saurabh/adbanner-test.git' \ No newline at end of file diff --git a/config/initializers/keyword_constraint.rb b/config/initializers/keyword_constraint.rb index adb8472..41a0b52 100644 --- a/config/initializers/keyword_constraint.rb +++ b/config/initializers/keyword_constraint.rb @@ -1,6 +1,6 @@ class KeywordConstraint def matches?(request) - keywords = %w{admin member desktop user} + keywords = %w{admin member desktop user signup login} keywords.all? { |k| !request.url.include?(k) } end end \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index b9c5176..08eb537 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -44,4 +44,37 @@ en: site: system_preference: System Preference - settings: Site Settings \ No newline at end of file + settings: Site Settings + + users: + admin_change_password: You cannot change your own password here! + avatar: Profile Picture + change_passwd: Password + setting_privilege: Privilege + email: Email + first_name: First Name + last_name: Last Name + male: Male + name: Name + valid_old_password: Current password doesn't match confirmation + new_password: New password + new_password_note: At least 6 characters + new_password_confirmation: Confirm new password + female: Female + unknown: Information Not Available + office_tel: Office Tel No. + office_tel_note: Public available + sid: ID No. + sid_note: Faculty ID No. or Student ID No. + sex: Gender + user_id: User Account + user_id_note: Should be more than 3 characters and less than 50 characters + user_id_not_null: User account cannot be null + user_id_length: User account should be more than 3 characters + user_id_error: Someone already use that user account + user_basic_id_form: Account Info. + user_basic_data: Personal Profile + + dots: ●●●●●● + register: Register + registered: Registered diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 96872f0..72b4d89 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -18,6 +18,42 @@ zh_tw: logout: 登出 dashboard_: 儀表版 desktop: 桌面 -site: - system_preference: 系統狀態 + + site: + system_preference: 系統狀態 + settings: 基本設定 + + users: + admin_change_password: 您不能在此處修改自己的密碼! + avatar: 大頭貼照 + change_passwd: 變更密碼 + setting_privilege: 權限設定 + email: 電子郵件 + first_name: 名字 + male: 男性 + name: 姓名 + valid_old_password: 目前的密碼不符合確認值 + new_password: 新密碼 + new_password_note: 至少6個字元 + new_password_confirmation: 確認新密碼 + female: 女性 + unknown: 未知 + last_name: 姓氏 + office_tel: 辦公室電話 + office_tel_note: 將公開於網頁 + sid: 編號 + sid_note: 教職員工編號或學生學號 + sex: 性別 + user_id: 使用者帳號 + user_id_note: 需介於3個字元至50個字元之間 + user_id_not_null: 使用者帳號不能是空值 + user_id_length: 使用者帳號至少需要3個字元 + user_id_error: 該使用者帳號已被使用 + user_basic_id_form: 帳號資料 + user_basic_data: 個人資料 + + dots: ●●●●●● + register: 註冊 + registered: 已註冊 + diff --git a/config/routes.rb b/config/routes.rb index 7afa392..c4e2662 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,5 @@ OrbitStore::Application.routes.draw do - resources :users - get "/pages/edit_view" => "pages#edit_view" get "/pages/preview" => "pages#preview" @@ -20,9 +18,11 @@ OrbitStore::Application.routes.draw do # You can have the root of your site routed with "root" root 'pages#home' - locales = Site.find_by(site_active: true).in_use_locales + locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_locales scope "(:locale)", locale: Regexp.new(locales.join("|")) do + resources :users + namespace :admin do resources :dashboards resources :items diff --git a/lib/orbit_app.rb b/lib/orbit_app.rb index aacb1f5..0e0429d 100644 --- a/lib/orbit_app.rb +++ b/lib/orbit_app.rb @@ -1,5 +1,6 @@ require 'orbit_app/helper/renderer' require 'orbit_app/helper/side_bar_renderer' +require "orbit_app/helper/context_link_renderer" require 'orbit_app/register_module' require 'orbit_app/module/registration' require 'orbit_app/module/side_bar' diff --git a/lib/orbit_app/helper/context_link_renderer.rb b/lib/orbit_app/helper/context_link_renderer.rb new file mode 100644 index 0000000..6755299 --- /dev/null +++ b/lib/orbit_app/helper/context_link_renderer.rb @@ -0,0 +1,12 @@ +module ContextLinkRenderer + include Renderer + + def render(request,params,current_module_app,belong_module_app) + @current_module_app = current_module_app + @belong_module_app = belong_module_app + @request = request + @params = params + content_tag :li, link_to(content_tag(:span, I18n.t(@label_i18n)), eval(@path)), :class => (active? ? 'active' : nil) + end + +end \ No newline at end of file diff --git a/lib/orbit_app/helper/side_bar_renderer.rb b/lib/orbit_app/helper/side_bar_renderer.rb index 7412dcd..609c7cd 100644 --- a/lib/orbit_app/helper/side_bar_renderer.rb +++ b/lib/orbit_app/helper/side_bar_renderer.rb @@ -10,7 +10,9 @@ module SideBarRenderer content_tag :div, class: "sub-nav-block #{@icon_class}" do concat content_tag :h4, I18n.t(@head_label) concat (content_tag :ul, class: "nav nav-list" do - + @context_links.sort_by {| obj | obj.priority}.map{ |link| + link.render(request, params, @current_module_app, @belong_module_app) + }.join.html_safe end) end end diff --git a/lib/orbit_app/module/side_bar.rb b/lib/orbit_app/module/side_bar.rb index 3605ad9..275744e 100644 --- a/lib/orbit_app/module/side_bar.rb +++ b/lib/orbit_app/module/side_bar.rb @@ -43,6 +43,7 @@ module OrbitApp def initialize(name = '',key,get_module_app,&block) @head_label = name + @context_links = [] @head_link = "" @app_base_path = '' @active_for_controllers = [] @@ -80,7 +81,23 @@ module OrbitApp end def active_for_controllers(var) - @active_for_controllers = var + @active_for_controllers = var + end + + def context_link(*var) + var[1].merge!({:module_app_key=>@module_app_key,:get_module_app=>@get_module_app}) unless @module_app_key.nil? + new_context_link = ContextLink.new(*var) + @context_links << new_context_link + end + + def finalize! + set_controllers_scope + # set_default_active_app_auth + current_priority = @context_links.count + @context_links.each do |t| + # t.set_module_app = @module_app + t.finalize! + end end protected @@ -89,13 +106,70 @@ module OrbitApp var = @active_for_controllers @active_for_controllers = [] var[:private].each do |controller| - @active_for_controllers << "admin/"+controller + @active_for_controllers << "#{locale}/admin/"+controller end unless var[:private].nil? var[:public].each do |controller| @active_for_controllers << controller end unless var[:public].nil? end end + + class ContextLink + include ContextLinkRenderer + attr_reader :label_i18n,:available_for,:priority,:path,:active_for_action + + def initialize(label_i18n="NoNameLink",options={}) + @label_i18n = label_i18n + @priority = options[:priority] || 0 + @path = options[:link_path] || "" + set_available_for_avoiding_sensitive_links(options[:available_for] ) + @active_for_action = options[:active_for_action] || [] + @module_app_key = options[:module_app_key] + @get_module_app = options[:get_module_app] + end + + def set_available_for_avoiding_sensitive_links(available_for) + sensitive_list = {} + sensitive_list[:module_app] =/.*manager_auth_proc.*/ + sensitive_list[:object_auth] = /.*object_auth.*/ + + sensitive_list.each do |index,regx| + if @path.match(regx) + @available_for = case index + when :module_app + [:admin] + when :object_auth + [:manager,:admin] + end #of case + end #of if + end #of each + @available_for = available_for if @available_for.nil? + end #of def + + def get_module_app + @get_module_app.call + end + + def active? + for_action = @active_for_action.blank? ? false : active_for_action? + for_action + end + + def active_for_action? + @active_for_action[controller] == action + end + + def finalize! + set_active_actions + end + + protected + + def set_active_actions + controller_action_hash = @active_for_action + @active_for_action = Hash[controller_action_hash.map{|controller,action| ["#{locale}/admin/"+controller.to_s,action.to_s]}] + end + end end end end \ No newline at end of file diff --git a/lib/orbit_category/categorizable.rb b/lib/orbit_category/categorizable.rb new file mode 100644 index 0000000..a3e1dff --- /dev/null +++ b/lib/orbit_category/categorizable.rb @@ -0,0 +1,19 @@ +module OrbitCategory + module Categorizable + def self.included(base) + base.field :category_id, type: BSON::ObjectId + end + + def category + Category.find(self.category_id) rescue nil + end + + def category=(cate) + self.category_id = Category.find(cate.id).id rescue nil + end + + def disable? + Category.find(self.category_id).disable? rescue nil + end + end +end \ No newline at end of file