update
This commit is contained in:
parent
2cfc4e719b
commit
80a1c0e173
|
@ -37,13 +37,11 @@ public/react/yarn.lock
|
|||
|
||||
# Ignore react node_modules
|
||||
public/system/*
|
||||
public/react/*
|
||||
/public/react/.cache
|
||||
/public/react/node_modules/
|
||||
/public/react/config/stats.json
|
||||
/public/react/stats.json
|
||||
/public/react/.idea/*
|
||||
/public/react/build/*
|
||||
/public/h5build
|
||||
/public/npm-debug.log
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ rails db:migrate RAILS_ENV=development
|
|||
git clone -b standalone https://git.trustie.net/jasder/build.git
|
||||
```
|
||||
|
||||
#### 12. 启动redis(此处已mac系统为例)
|
||||
#### 12. 启动redis(此处以macOS系统为例)
|
||||
```bash
|
||||
redis-server&
|
||||
```
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
class AccountsController < ApplicationController
|
||||
include ApplicationHelper
|
||||
|
||||
#skip_before_action :check_account, :only => [:logout]
|
||||
|
||||
def index
|
||||
render json: session
|
||||
end
|
||||
|
@ -139,15 +137,17 @@ class AccountsController < ApplicationController
|
|||
tip_exception(-1, interactor.error)
|
||||
end
|
||||
rescue Register::BaseForm::EmailError => e
|
||||
render_error(-2, e.message)
|
||||
render_result(-2, e.message)
|
||||
rescue Register::BaseForm::LoginError => e
|
||||
render_error(-3, e.message)
|
||||
render_result(-3, e.message)
|
||||
rescue Register::BaseForm::PhoneError => e
|
||||
render_error(-4, e.message)
|
||||
render_result(-4, e.message)
|
||||
rescue Register::BaseForm::PasswordFormatError => e
|
||||
render_error(-5, e.message)
|
||||
render_result(-5, e.message)
|
||||
rescue Register::BaseForm::PasswordConfirmationError => e
|
||||
render_result(-7, e.message)
|
||||
rescue Register::BaseForm::VerifiCodeError => e
|
||||
render_error(-6, e.message)
|
||||
render_result(-6, e.message)
|
||||
rescue Exception => e
|
||||
Gitea::User::DeleteService.call(user.login) unless user.nil?
|
||||
uid_logger_error(e.message)
|
||||
|
@ -157,7 +157,7 @@ class AccountsController < ApplicationController
|
|||
|
||||
# 用户登录
|
||||
def login
|
||||
Users::LoginForm.new(account_params).validate!
|
||||
Users::LoginForm.new(login_params).validate!
|
||||
@user = User.try_to_login(params[:login], params[:password])
|
||||
|
||||
return normal_status(-2, "错误的账号或密码") if @user.blank?
|
||||
|
@ -206,28 +206,27 @@ class AccountsController < ApplicationController
|
|||
# 忘记密码
|
||||
def reset_password
|
||||
begin
|
||||
code = params[:code]
|
||||
login_type = phone_mail_type(params[:login].strip)
|
||||
# 获取验证码
|
||||
if login_type == 1
|
||||
phone = params[:login]
|
||||
verifi_code = VerificationCode.where(phone: phone, code: code, code_type: 2).last
|
||||
user = User.find_by_phone(phone)
|
||||
else
|
||||
email = params[:login]
|
||||
verifi_code = VerificationCode.where(email: email, code: code, code_type: 3).last
|
||||
user = User.find_by_mail(email) #这里有问题,应该是为email,而不是mail 6.13-hs
|
||||
end
|
||||
return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
|
||||
return normal_status(-2, "验证码已失效") if !verifi_code&.effective?
|
||||
return normal_status(-1, "8~16位密码,支持字母数字和符号") unless params[:new_password] =~ CustomRegexp::PASSWORD
|
||||
Accounts::ResetPasswordForm.new(reset_password_params).validate!
|
||||
|
||||
user.password, user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
||||
ActiveRecord::Base.transaction do
|
||||
user.save!
|
||||
LimitForbidControl::UserLogin.new(user).clear
|
||||
end
|
||||
sucess_status
|
||||
user = find_user
|
||||
return render_error('未找到相关账号') if user.blank?
|
||||
|
||||
user = Accounts::ResetPasswordService.call(user, reset_password_params)
|
||||
LimitForbidControl::UserLogin.new(user).clear if user.save!
|
||||
|
||||
render_ok
|
||||
rescue Register::BaseForm::EmailError => e
|
||||
render_result(-2, e.message)
|
||||
rescue Register::BaseForm::PhoneError => e
|
||||
render_result(-4, e.message)
|
||||
rescue Register::BaseForm::PasswordFormatError => e
|
||||
render_result(-5, e.message)
|
||||
rescue Register::BaseForm::PasswordConfirmationError => e
|
||||
render_result(-7, e.message)
|
||||
rescue Register::BaseForm::VerifiCodeError => e
|
||||
render_result(-6, e.message)
|
||||
rescue ActiveRecord::Rollback => e
|
||||
render_result(-1, "服务器异常")
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
|
@ -356,7 +355,7 @@ class AccountsController < ApplicationController
|
|||
params.require(:user).permit(:login, :email, :phone)
|
||||
end
|
||||
|
||||
def account_params
|
||||
def login_params
|
||||
params.require(:account).permit(:login, :password)
|
||||
end
|
||||
|
||||
|
@ -365,7 +364,16 @@ class AccountsController < ApplicationController
|
|||
end
|
||||
|
||||
def register_params
|
||||
params.permit(:login, :namespace, :password, :code)
|
||||
params.permit(:login, :namespace, :password, :password_confirmation, :code)
|
||||
end
|
||||
|
||||
def reset_password_params
|
||||
params.permit(:login, :password, :password_confirmation, :code)
|
||||
end
|
||||
|
||||
def find_user
|
||||
phone_or_mail = strip(reset_password_params[:login])
|
||||
User.where("phone = :search OR mail = :search", search: phone_or_mail).last
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
class Admins::Topic::ActivityForumsController < Admins::Topic::BaseController
|
||||
before_action :find_activity_forum, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
q = ::Topic::ActivityForum.ransack(title_cont: params[:search])
|
||||
activity_forums = q.result(distinct: true)
|
||||
@activity_forums = paginate(activity_forums)
|
||||
end
|
||||
|
||||
def new
|
||||
@activity_forum = ::Topic::ActivityForum.new
|
||||
end
|
||||
|
||||
def create
|
||||
@activity_forum = ::Topic::ActivityForum.new(activity_forum_params)
|
||||
if @activity_forum.save
|
||||
redirect_to admins_topic_activity_forums_path
|
||||
flash[:success] = "新增平台动态成功"
|
||||
else
|
||||
redirect_to admins_topic_activity_forums_path
|
||||
flash[:danger] = "新增平台动态失败"
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@activity_forum.attributes = activity_forum_params
|
||||
if @activity_forum.save
|
||||
redirect_to admins_topic_activity_forums_path
|
||||
flash[:success] = "更新平台动态成功"
|
||||
else
|
||||
redirect_to admins_topic_activity_forums_path
|
||||
flash[:danger] = "更新平台动态失败"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @activity_forum.destroy
|
||||
redirect_to admins_topic_activity_forums_path
|
||||
flash[:success] = "删除平台动态成功"
|
||||
else
|
||||
redirect_to admins_topic_activity_forums_path
|
||||
flash[:danger] = "删除平台动态失败"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_activity_forum
|
||||
@activity_forum = ::Topic::ActivityForum.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def activity_forum_params
|
||||
params.require(:topic_activity_forum).permit(:title, :uuid, :url, :order_index)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,57 @@
|
|||
class Admins::Topic::BannersController < Admins::Topic::BaseController
|
||||
before_action :find_banner, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@banners = paginate(::Topic::Banner)
|
||||
end
|
||||
|
||||
def new
|
||||
@banner = ::Topic::Banner.new
|
||||
end
|
||||
|
||||
def create
|
||||
@banner = ::Topic::Banner.new(banner_params)
|
||||
if @banner.save
|
||||
save_image_file(params[:image], @banner)
|
||||
redirect_to admins_topic_banners_path
|
||||
flash[:success] = "新增banner成功"
|
||||
else
|
||||
redirect_to admins_topic_banners_path
|
||||
flash[:danger] = "新增banner失败"
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@banner.attributes = banner_params
|
||||
if @banner.save
|
||||
save_image_file(params[:image], @banner)
|
||||
redirect_to admins_topic_banners_path
|
||||
flash[:success] = "更新banner成功"
|
||||
else
|
||||
redirect_to admins_topic_banners_path
|
||||
flash[:danger] = "更新banner失败"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @banner.destroy
|
||||
redirect_to admins_topic_banners_path
|
||||
flash[:success] = "删除banner成功"
|
||||
else
|
||||
redirect_to admins_topic_banners_path
|
||||
flash[:danger] = "删除banner失败"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_banner
|
||||
@banner = ::Topic::Banner.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def banner_params
|
||||
params.require(:topic_banner).permit(:title, :order_index)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
class Admins::Topic::BaseController < Admins::BaseController
|
||||
|
||||
protected
|
||||
def save_image_file(file, topic)
|
||||
return unless file.present? && file.is_a?(ActionDispatch::Http::UploadedFile)
|
||||
|
||||
file_path = Util::FileManage.source_disk_filename(topic, 'image')
|
||||
File.delete(file_path) if File.exist?(file_path) # 删除之前的文件
|
||||
Util.write_file(file, file_path)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,57 @@
|
|||
class Admins::Topic::CardsController < Admins::Topic::BaseController
|
||||
before_action :find_card, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
q = ::Topic::Card.ransack(title_cont: params[:search])
|
||||
cards = q.result(distinct: true)
|
||||
@cards = paginate(cards)
|
||||
end
|
||||
|
||||
def new
|
||||
@card = ::Topic::Card.new
|
||||
end
|
||||
|
||||
def create
|
||||
@card = ::Topic::Card.new(card_params)
|
||||
if @card.save
|
||||
redirect_to admins_topic_cards_path
|
||||
flash[:success] = "新增合作单位成功"
|
||||
else
|
||||
redirect_to admins_topic_cards_path
|
||||
flash[:danger] = "新增合作单位失败"
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@card.attributes = card_params
|
||||
if @card.save
|
||||
redirect_to admins_topic_cards_path
|
||||
flash[:success] = "更新合作单位成功"
|
||||
else
|
||||
redirect_to admins_topic_cards_path
|
||||
flash[:danger] = "更新合作单位失败"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @card.destroy
|
||||
redirect_to admins_topic_cards_path
|
||||
flash[:success] = "删除合作单位成功"
|
||||
else
|
||||
redirect_to admins_topic_cards_path
|
||||
flash[:danger] = "删除合作单位失败"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_card
|
||||
@card = ::Topic::Card.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def card_params
|
||||
params.require(:topic_card).permit(:title, :url, :order_index)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,57 @@
|
|||
class Admins::Topic::CooperatorsController < Admins::Topic::BaseController
|
||||
before_action :find_cooperator, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@cooperators = paginate(::Topic::Cooperator)
|
||||
end
|
||||
|
||||
def new
|
||||
@cooperator = ::Topic::Cooperator.new
|
||||
end
|
||||
|
||||
def create
|
||||
@cooperator = ::Topic::Cooperator.new(cooperator_params)
|
||||
if @cooperator.save
|
||||
save_image_file(params[:image], @cooperator)
|
||||
redirect_to admins_topic_cooperators_path
|
||||
flash[:success] = "新增合作单位成功"
|
||||
else
|
||||
redirect_to admins_topic_cooperators_path
|
||||
flash[:danger] = "新增合作单位失败"
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@cooperator.attributes = cooperator_params
|
||||
if @cooperator.save
|
||||
save_image_file(params[:image], @cooperator)
|
||||
redirect_to admins_topic_cooperators_path
|
||||
flash[:success] = "更新合作单位成功"
|
||||
else
|
||||
redirect_to admins_topic_cooperators_path
|
||||
flash[:danger] = "更新合作单位失败"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @cooperator.destroy
|
||||
redirect_to admins_topic_cooperators_path
|
||||
flash[:success] = "删除合作单位成功"
|
||||
else
|
||||
redirect_to admins_topic_cooperators_path
|
||||
flash[:danger] = "删除合作单位失败"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_cooperator
|
||||
@cooperator = ::Topic::Cooperator.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def cooperator_params
|
||||
params.require(:topic_cooperator).permit(:title, :url, :order_index)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,57 @@
|
|||
class Admins::Topic::ExcellentProjectsController < Admins::Topic::BaseController
|
||||
before_action :find_excellent_project, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
q = ::Topic::ExcellentProject.ransack(title_cont: params[:search])
|
||||
excellent_projects = q.result(distinct: true)
|
||||
@excellent_projects = paginate(excellent_projects)
|
||||
end
|
||||
|
||||
def new
|
||||
@excellent_project = ::Topic::ExcellentProject.new
|
||||
end
|
||||
|
||||
def create
|
||||
@excellent_project = ::Topic::ExcellentProject.new(excellent_project_params)
|
||||
if @excellent_project.save
|
||||
redirect_to admins_topic_excellent_projects_path
|
||||
flash[:success] = "新增优秀仓库成功"
|
||||
else
|
||||
redirect_to admins_topic_excellent_projects_path
|
||||
flash[:danger] = "新增优秀仓库失败"
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@excellent_project.attributes = excellent_project_params
|
||||
if @excellent_project.save
|
||||
redirect_to admins_topic_excellent_projects_path
|
||||
flash[:success] = "更新优秀仓库成功"
|
||||
else
|
||||
redirect_to admins_topic_excellent_projects_path
|
||||
flash[:danger] = "更新优秀仓库失败"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @excellent_project.destroy
|
||||
redirect_to admins_topic_excellent_projects_path
|
||||
flash[:success] = "删除优秀仓库成功"
|
||||
else
|
||||
redirect_to admins_topic_excellent_projects_path
|
||||
flash[:danger] = "删除优秀仓库失败"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_excellent_project
|
||||
@excellent_project = ::Topic::ExcellentProject.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def excellent_project_params
|
||||
params.require(:topic_excellent_project).permit(:title, :uuid, :url, :order_index)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,57 @@
|
|||
class Admins::Topic::ExperienceForumsController < Admins::Topic::BaseController
|
||||
before_action :find_experience_forum, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
q = ::Topic::ExperienceForum.ransack(title_cont: params[:search])
|
||||
experience_forums = q.result(distinct: true)
|
||||
@experience_forums = paginate(experience_forums)
|
||||
end
|
||||
|
||||
def new
|
||||
@experience_forum = ::Topic::ExperienceForum.new
|
||||
end
|
||||
|
||||
def create
|
||||
@experience_forum = ::Topic::ExperienceForum.new(experience_forum_params)
|
||||
if @experience_forum.save
|
||||
redirect_to admins_topic_experience_forums_path
|
||||
flash[:success] = "新增经验分享成功"
|
||||
else
|
||||
redirect_to admins_topic_experience_forums_path
|
||||
flash[:danger] = "新增经验分享失败"
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@experience_forum.attributes = experience_forum_params
|
||||
if @experience_forum.save
|
||||
redirect_to admins_topic_experience_forums_path
|
||||
flash[:success] = "更新经验分享成功"
|
||||
else
|
||||
redirect_to admins_topic_experience_forums_path
|
||||
flash[:danger] = "更新经验分享失败"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @experience_forum.destroy
|
||||
redirect_to admins_topic_experience_forums_path
|
||||
flash[:success] = "删除经验分享成功"
|
||||
else
|
||||
redirect_to admins_topic_experience_forums_path
|
||||
flash[:danger] = "删除经验分享失败"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_experience_forum
|
||||
@experience_forum = ::Topic::ExperienceForum.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def experience_forum_params
|
||||
params.require(:topic_experience_forum).permit(:title, :uuid, :url, :order_index)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,57 @@
|
|||
class Admins::Topic::PinnedForumsController < Admins::Topic::BaseController
|
||||
before_action :find_pinned_forum, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
q = ::Topic::PinnedForum.ransack(title_cont: params[:search])
|
||||
pinned_forums = q.result(distinct: true)
|
||||
@pinned_forums = paginate(pinned_forums)
|
||||
end
|
||||
|
||||
def new
|
||||
@pinned_forum = ::Topic::PinnedForum.new
|
||||
end
|
||||
|
||||
def create
|
||||
@pinned_forum = ::Topic::PinnedForum.new(pinned_forum_params)
|
||||
if @pinned_forum.save
|
||||
redirect_to admins_topic_pinned_forums_path
|
||||
flash[:success] = "新增精选文章成功"
|
||||
else
|
||||
redirect_to admins_topic_pinned_forums_path
|
||||
flash[:danger] = "新增精选文章失败"
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@pinned_forum.attributes = pinned_forum_params
|
||||
if @pinned_forum.save
|
||||
redirect_to admins_topic_pinned_forums_path
|
||||
flash[:success] = "更新精选文章成功"
|
||||
else
|
||||
redirect_to admins_topic_pinned_forums_path
|
||||
flash[:danger] = "更新精选文章失败"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @pinned_forum.destroy
|
||||
redirect_to admins_topic_pinned_forums_path
|
||||
flash[:success] = "删除精选文章成功"
|
||||
else
|
||||
redirect_to admins_topic_pinned_forums_path
|
||||
flash[:danger] = "删除精选文章失败"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_pinned_forum
|
||||
@pinned_forum = ::Topic::PinnedForum.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def pinned_forum_params
|
||||
params.require(:topic_pinned_forum).permit(:title, :uuid, :url, :order_index)
|
||||
end
|
||||
end
|
|
@ -26,7 +26,8 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
|
||||
OPENKEY = "79e33abd4b6588941ab7622aed1e67e8"
|
||||
OPENKEY = Rails.application.config_for(:configuration)['sign_key'] || "79e33abd4b6588941ab7622aed1e67e8"
|
||||
|
||||
|
||||
helper_method :current_user, :base_url
|
||||
|
||||
|
@ -264,7 +265,6 @@ class ApplicationController < ActionController::Base
|
|||
User.current = user
|
||||
end
|
||||
end
|
||||
|
||||
# if !User.current.logged? && Rails.env.development?
|
||||
# User.current = User.find 1
|
||||
# end
|
||||
|
@ -336,11 +336,6 @@ class ApplicationController < ActionController::Base
|
|||
@message = message
|
||||
end
|
||||
|
||||
# 实训等对应的仓库地址
|
||||
def repo_ip_url(repo_path)
|
||||
"#{edu_setting('git_address_ip')}/#{repo_path}"
|
||||
end
|
||||
|
||||
def repo_url(repo_path)
|
||||
"#{edu_setting('git_address_domain')}/#{repo_path}"
|
||||
end
|
||||
|
@ -609,7 +604,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def kaminari_paginate(relation)
|
||||
limit = params[:limit] || params[:per_page]
|
||||
limit = (limit.to_i.zero? || limit.to_i > 15) ? 15 : limit.to_i
|
||||
limit = (limit.to_i.zero? || limit.to_i > 20) ? 20 : limit.to_i
|
||||
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
|
||||
|
||||
relation.page(page).per(limit)
|
||||
|
@ -617,7 +612,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def kaminari_array_paginate(relation)
|
||||
limit = params[:limit] || params[:per_page]
|
||||
limit = (limit.to_i.zero? || limit.to_i > 15) ? 15 : limit.to_i
|
||||
limit = (limit.to_i.zero? || limit.to_i > 20) ? 20 : limit.to_i
|
||||
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
|
||||
|
||||
Kaminari.paginate_array(relation).page(page).per(limit)
|
||||
|
@ -742,37 +737,10 @@ class ApplicationController < ActionController::Base
|
|||
render json: exception.tip_json
|
||||
end
|
||||
|
||||
def render_parameter_missing
|
||||
render json: { status: -1, message: '参数缺失' }
|
||||
end
|
||||
|
||||
def set_export_cookies
|
||||
cookies[:fileDownload] = true
|
||||
end
|
||||
|
||||
# 149课程的评审用户数据创建(包含创建课堂学生)
|
||||
def open_class_user
|
||||
user = User.find_by(login: "OpenClassUser")
|
||||
unless user
|
||||
ActiveRecord::Base.transaction do
|
||||
user_params = {status: 1, login: "OpenClassUser", lastname: "开放课程",
|
||||
nickname: "开放课程", professional_certification: 1, certification: 1, grade: 0,
|
||||
password: "12345678", phone: "11122223333", profile_completed: 1}
|
||||
user = User.create!(user_params)
|
||||
|
||||
UserExtension.create!(user_id: user.id, gender: 0, school_id: 3396, :identity => 1, :student_id => "openclassuser") # 3396
|
||||
|
||||
subject = Subject.find_by(id: 149)
|
||||
if subject
|
||||
subject.courses.each do |course|
|
||||
CourseMember.create!(course_id: course.id, role: 3, user_id: user.id) if !course.course_members.exists?(user_id: user.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
user
|
||||
end
|
||||
|
||||
# 记录热门搜索关键字
|
||||
def record_search_keyword
|
||||
keyword = params[:keyword].to_s.strip
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
module RegisterHelper
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def autologin_register(username, email, password, platform= 'forge')
|
||||
def autologin_register(username, email, password, platform= 'forge', need_edit_info = false)
|
||||
result = {message: nil, user: nil}
|
||||
|
||||
user = User.new(admin: false, login: username, mail: email, type: "User")
|
||||
user.password = password
|
||||
user.platform = platform
|
||||
if need_edit_info
|
||||
user.need_edit_info
|
||||
else
|
||||
user.activate
|
||||
end
|
||||
|
||||
return unless user.valid?
|
||||
|
||||
|
@ -27,4 +31,31 @@ module RegisterHelper
|
|||
result
|
||||
end
|
||||
|
||||
def autosync_register_trustie(username, password, email, lastname="")
|
||||
config = Rails.application.config_for(:configuration).symbolize_keys!
|
||||
|
||||
api_host = config[:sync_url]
|
||||
|
||||
return if api_host.blank?
|
||||
|
||||
url = "#{api_host}/api/v1/users/common"
|
||||
sync_json = {
|
||||
"mail": email,
|
||||
"password": password,
|
||||
"login": username,
|
||||
"lastname": lastname
|
||||
}.compact
|
||||
uri = URI.parse(url)
|
||||
|
||||
if api_host
|
||||
http = Net::HTTP.new(uri.hostname, uri.port)
|
||||
|
||||
if api_host.include?("https://")
|
||||
http.use_ssl = true
|
||||
end
|
||||
|
||||
http.send_request('POST', uri.path, sync_json.to_json, {'Content-Type' => 'application/json'})
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3,8 +3,8 @@ module RenderHelper
|
|||
render json: { status: 0, message: 'success' }.merge(data)
|
||||
end
|
||||
|
||||
def render_error(status = -1, message = '')
|
||||
render json: { status: status, message: message }
|
||||
def render_error(message = '')
|
||||
render json: { status: -1, message: message }
|
||||
end
|
||||
|
||||
def render_not_acceptable(message = '请求已拒绝')
|
||||
|
@ -28,4 +28,8 @@ module RenderHelper
|
|||
def render_result(status=1, message='success')
|
||||
render json: { status: status, message: message }
|
||||
end
|
||||
|
||||
def render_parameter_missing
|
||||
render json: { status: -1, message: '参数缺失' }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,6 +2,7 @@ class Oauth::BaseController < ActionController::Base
|
|||
include RenderHelper
|
||||
include LoginHelper
|
||||
include ControllerRescueHandler
|
||||
include LoggerHelper
|
||||
# include LaboratoryHelper
|
||||
|
||||
skip_before_action :verify_authenticity_token
|
||||
|
@ -11,6 +12,18 @@ class Oauth::BaseController < ActionController::Base
|
|||
end
|
||||
|
||||
private
|
||||
def tip_exception(status = -1, message)
|
||||
raise Educoder::TipException.new(status, message)
|
||||
end
|
||||
|
||||
def tip_show_exception(status = -2, message)
|
||||
raise Educoder::TipException.new(status, message)
|
||||
end
|
||||
|
||||
def tip_show(exception)
|
||||
uid_logger("Tip show status is #{exception.status}, message is #{exception.message}")
|
||||
render json: exception.tip_json
|
||||
end
|
||||
|
||||
def session_user_id
|
||||
# session[:user_id]
|
||||
|
@ -48,4 +61,13 @@ class Oauth::BaseController < ActionController::Base
|
|||
Rails.logger.info("[wechat] set session unionid: #{unionid}")
|
||||
session[:unionid] = unionid
|
||||
end
|
||||
|
||||
def session_edulogin
|
||||
session[:edulogin]
|
||||
end
|
||||
|
||||
def set_session_edulogin(login)
|
||||
Rails.logger.info("[educoder] set sesstion edulogin: #{login}")
|
||||
session[:edulogin] = login
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class Oauth::EducoderController < Oauth::BaseController
|
||||
include RegisterHelper
|
||||
|
||||
def bind
|
||||
begin
|
||||
login = params[:login]
|
||||
|
@ -32,4 +34,41 @@ class Oauth::EducoderController < Oauth::BaseController
|
|||
render_error(ex.message)
|
||||
end
|
||||
end
|
||||
|
||||
# 需要educoder那边设置回调地址
|
||||
def create
|
||||
begin
|
||||
code = params['code'].to_s.strip
|
||||
tip_exception("code不能为空") if code.blank?
|
||||
|
||||
new_user = false
|
||||
result = EducoderOauth::Service.access_token(code)
|
||||
result = EducoderOauth::Service.user_info(result[:access_token])
|
||||
|
||||
# 存在该用户
|
||||
open_user = OpenUsers::Educoder.find_by(uid: result['login'])
|
||||
if open_user.present? && open_user.user.present?
|
||||
successful_authentication(open_user.user)
|
||||
else
|
||||
if current_user.blank? || !current_user.logged?
|
||||
new_user = true
|
||||
login = User.generate_login('E')
|
||||
reg_result = autologin_register(login,"#{login}@forge.com", "Ec#{login}2021#", 'educoder', true)
|
||||
if reg_result[:message].blank?
|
||||
open_user = OpenUsers::Educoder.create!(user_id: reg_result[:user][:id], uid: result['login'], extra: result)
|
||||
autosync_register_trustie(login, "Ec#{login}2021#", "#{login}@forge.com")
|
||||
successful_authentication(open_user.user)
|
||||
else
|
||||
render_error(reg_result[:message])
|
||||
end
|
||||
else
|
||||
OpenUsers::Educoder.create!(user: current_user, uid: result['login'], extra: result)
|
||||
end
|
||||
end
|
||||
|
||||
redirect_to root_path(new_user: new_user)
|
||||
rescue Exception => ex
|
||||
render_error(ex.message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -61,6 +61,7 @@ class OauthController < ApplicationController
|
|||
login = params[:login]
|
||||
email = params[:mail]
|
||||
password = params[:password]
|
||||
lastname = params[:lastname]
|
||||
callback_url = params[:callback_url]
|
||||
platform = params[:plathform] || 'educoder'
|
||||
|
||||
|
@ -72,8 +73,11 @@ class OauthController < ApplicationController
|
|||
if result[:message].blank?
|
||||
logger.info "[Oauth educoer] ====auto_register success"
|
||||
user = User.find result[:user][:id]
|
||||
successful_authentication(user)
|
||||
user.update_column(:lastname, params[:lastname])
|
||||
autosync_register_trustie(login, password, email, lastname)
|
||||
|
||||
OpenUsers::Educoder.create!(user: user, uid: user.login)
|
||||
successful_authentication(user)
|
||||
|
||||
render json: { callback_url: callback_url }
|
||||
# redirect_to callback_url
|
||||
|
|
|
@ -347,7 +347,7 @@ class RepositoriesController < ApplicationController
|
|||
local_requests = PullRequest.new(local_params.merge(user_id: current_user.try(:id), project_id: @project.id, issue_id: @pull_issue.id))
|
||||
if local_requests.save
|
||||
gitea_request = Gitea::PullRequest::CreateService.new(current_user.try(:gitea_token), @owner.login, @project.try(:identifier), requests_params).call
|
||||
if gitea_request[:status] == :success && local_requests.update_attributes(gpid: gitea_request["body"]["number"])
|
||||
if gitea_request[:status] == :success && local_requests.update_attributes(gitea_number: gitea_request["body"]["number"])
|
||||
local_requests.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@ class SettingsController < ApplicationController
|
|||
get_add_menu
|
||||
get_common_menu
|
||||
get_personal_menu
|
||||
get_third_party
|
||||
get_top_system_notification
|
||||
end
|
||||
|
||||
|
@ -40,6 +41,14 @@ class SettingsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def get_third_party
|
||||
@third_party = []
|
||||
@third_party << {
|
||||
name: 'educoder',
|
||||
url: EducoderOauth.oauth_url
|
||||
}
|
||||
end
|
||||
|
||||
def get_top_system_notification
|
||||
@top_system_notification = SystemNotification.is_top.first
|
||||
end
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class TopicsController < ApplicationController
|
||||
|
||||
def index
|
||||
return render_not_found("请输入正确的数据类型") unless params[:topic_type].present?
|
||||
scope = Topic.with_single_type(params[:topic_type])
|
||||
@topics = kaminari_paginate(scope)
|
||||
end
|
||||
|
||||
end
|
|
@ -275,7 +275,7 @@ class UsersController < ApplicationController
|
|||
|
||||
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params)
|
||||
if interactor.success?
|
||||
user.update!(password: params[:password], mail: params[:email], status: User::STATUS_EDIT_INFO)
|
||||
user.update!(password: params[:password], mail: params[:email], status: User::STATUS_ACTIVE)
|
||||
render_ok
|
||||
else
|
||||
render_error(interactor.error)
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
module Accounts
|
||||
class ResetPasswordForm < ::BaseForm
|
||||
# login 邮箱、手机号
|
||||
# code 验证码
|
||||
# type: 1:手机号注册;2:邮箱注册
|
||||
attr_accessor :login, :password, :password_confirmation, :code
|
||||
|
||||
validates :login, :code, :password, :password_confirmation, presence: true, allow_blank: false
|
||||
validate :check!
|
||||
|
||||
def check!
|
||||
Rails.logger.info "ResetPasswordForm params: code: #{code} login: #{login}
|
||||
password: #{password} password_confirmation: #{password_confirmation}"
|
||||
|
||||
type = phone_mail_type(login)
|
||||
|
||||
db_verifi_code =
|
||||
if type == 1
|
||||
check_phone_format(login)
|
||||
VerificationCode.where(phone: login, code: code, code_type: 2).last
|
||||
elsif type == 0
|
||||
check_email_format(login)
|
||||
VerificationCode.where(email: login, code: code, code_type: 3).last
|
||||
end
|
||||
|
||||
check_password(password)
|
||||
check_password_confirmation(password, password_confirmation)
|
||||
check_verifi_code(db_verifi_code, code)
|
||||
end
|
||||
|
||||
def check_phone_format(phone)
|
||||
phone = strip(phone)
|
||||
raise LoginError, "登录名格式有误" unless phone =~ CustomRegexp::LOGIN
|
||||
end
|
||||
|
||||
def check_email_format(mail)
|
||||
mail = strip(mail)
|
||||
raise EmailError, "邮件格式有误" unless mail =~ CustomRegexp::EMAIL
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,14 @@
|
|||
class BaseForm
|
||||
include ActiveModel::Model
|
||||
|
||||
Error = Class.new(StandardError)
|
||||
EmailError = Class.new(Error)
|
||||
LoginError = Class.new(Error)
|
||||
PhoneError = Class.new(Error)
|
||||
PasswordFormatError = Class.new(Error)
|
||||
VerifiCodeError = Class.new(Error)
|
||||
PasswordConfirmationError = Class.new(Error)
|
||||
|
||||
def check_project_category(project_category_id)
|
||||
unless project_category_id == ''
|
||||
raise "project_category_id参数值无效." if project_category_id && !ProjectCategory.exists?(project_category_id)
|
||||
|
@ -26,8 +34,35 @@ class BaseForm
|
|||
raise "项目标识已被占用." if ReversedKeyword.check_exists?(repository_name)
|
||||
end
|
||||
|
||||
def check_password(password)
|
||||
password = strip(password)
|
||||
raise PasswordFormatError, "密码8~16位密码,支持字母数字和符号" unless password =~ CustomRegexp::PASSWORD
|
||||
end
|
||||
|
||||
def check_password_confirmation(password, password_confirmation)
|
||||
password = strip(password)
|
||||
password_confirmation = strip(password_confirmation)
|
||||
|
||||
raise PasswordFormatError, "确认密码为8~16位密码,支持字母数字和符号" unless password_confirmation =~ CustomRegexp::PASSWORD
|
||||
raise PasswordConfirmationError, "两次输入的密码不一致" unless password == password_confirmation
|
||||
end
|
||||
|
||||
def check_verifi_code(verifi_code, code)
|
||||
code = strip(code)
|
||||
# return if code == "123123" # TODO 万能验证码,用于测试
|
||||
|
||||
raise VerifiCodeError, "验证码不正确" if verifi_code&.code != code
|
||||
raise VerifiCodeError, "验证码已失效" if !verifi_code&.effective?
|
||||
end
|
||||
|
||||
private
|
||||
def strip(str)
|
||||
str.to_s.strip.presence
|
||||
end
|
||||
|
||||
# 1 手机类型;0 邮箱类型
|
||||
# 注意新版的login是自动名生成的
|
||||
def phone_mail_type value
|
||||
value =~ /^1\d{10}$/ ? 1 : 0
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,13 +2,6 @@ module Register
|
|||
class BaseForm < ::BaseForm
|
||||
include ActiveModel::Model
|
||||
|
||||
Error = Class.new(StandardError)
|
||||
EmailError = Class.new(Error)
|
||||
LoginError = Class.new(Error)
|
||||
PhoneError = Class.new(Error)
|
||||
PasswordFormatError = Class.new(Error)
|
||||
VerifiCodeError = Class.new(Error)
|
||||
|
||||
private
|
||||
def check_login(login)
|
||||
login = strip(login)
|
||||
|
@ -33,19 +26,5 @@ module Register
|
|||
phone_exist = Owner.exists?(phone: phone)
|
||||
raise PhoneError, '手机号已被使用' if phone_exist
|
||||
end
|
||||
|
||||
def check_password(password)
|
||||
password = strip(password)
|
||||
raise PasswordFormatError, "8~16位密码,支持字母数字和符号" unless password =~ CustomRegexp::PASSWORD
|
||||
end
|
||||
|
||||
def check_verifi_code(verifi_code, code)
|
||||
code = strip(code)
|
||||
# return if code == "123123" # TODO 万能验证码,用于测试
|
||||
|
||||
raise VerifiCodeError, "验证码不正确" if verifi_code&.code != code
|
||||
raise VerifiCodeError, "验证码已失效" if !verifi_code&.effective?
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,13 +3,16 @@ module Register
|
|||
# login 登陆方式,支持邮箱、登陆、手机号等
|
||||
# namespace 用户空间地址
|
||||
# type: 1:手机号注册;2:邮箱注册
|
||||
attr_accessor :login, :namespace, :password, :code, :type
|
||||
attr_accessor :login, :namespace, :password, :password_confirmation, :code, :type
|
||||
|
||||
validates :login, :code, :password, :namespace, presence: true
|
||||
validates :login, :code, :password, :password_confirmation, :namespace, presence: true, allow_blank: false
|
||||
validate :check!
|
||||
|
||||
def check!
|
||||
Rails.logger.info "Register::Form params: code: #{code}; login: #{login}; namespace: #{namespace}; password: #{password}; type: #{type}"
|
||||
Rails.logger.info "Register::Form params: code: #{code}; login: #{login};
|
||||
namespace: #{namespace}; password: #{password}; password_confirmation: #{password_confirmation}"
|
||||
|
||||
type = phone_mail_type(strip(login))
|
||||
db_verifi_code =
|
||||
if type == 1
|
||||
check_phone(login)
|
||||
|
@ -22,6 +25,7 @@ module Register
|
|||
check_login(namespace)
|
||||
check_verifi_code(db_verifi_code, code)
|
||||
check_password(password)
|
||||
check_password_confirmation(password, password_confirmation)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -470,4 +470,8 @@ module ApplicationHelper
|
|||
value =~ /^1\d{10}$/ ? 1 : 0
|
||||
end
|
||||
|
||||
def strip(str)
|
||||
str.to_s.strip.presence
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
module EducoderOauth
|
||||
class << self
|
||||
attr_accessor :client_id, :client_secret, :base_url, :redirect_uri
|
||||
|
||||
def logger
|
||||
@_logger ||= STDOUT
|
||||
end
|
||||
|
||||
def logger=(l)
|
||||
@_logger = l
|
||||
end
|
||||
|
||||
def oauth_url
|
||||
"#{base_url}/oauth2?call_url=/oauth/authorize?client_id=#{client_id}&redirect_uri=#{URI.encode_www_form_component(redirect_uri)}&response_type=code"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -0,0 +1,37 @@
|
|||
require 'oauth2'
|
||||
|
||||
module EducoderOauth::Service
|
||||
module_function
|
||||
|
||||
def request(method, url, params)
|
||||
begin
|
||||
Rails.logger.info("[EducoderOauth] [#{method.to_s.upcase}] #{url} || #{params}")
|
||||
|
||||
client = Faraday.new(url: EducoderOauth.base_url)
|
||||
response = client.public_send(method, url, params)
|
||||
result = JSON.parse(response.body)
|
||||
|
||||
Rails.logger.info("[EducoderOauth] [#{response.status}] #{result}")
|
||||
|
||||
result
|
||||
rescue Exception => e
|
||||
raise Educoder::TipException.new(e.message)
|
||||
end
|
||||
end
|
||||
|
||||
def access_token(code)
|
||||
begin
|
||||
Rails.logger.info("[EducoderOauth] [code] #{code} ")
|
||||
Rails.logger.info("[EducoderOauth] [redirect_uri] #{EducoderOauth.redirect_uri} ")
|
||||
client = OAuth2::Client.new(EducoderOauth.client_id, EducoderOauth.client_secret, site: EducoderOauth.base_url)
|
||||
result = client.auth_code.get_token(code, redirect_uri: EducoderOauth.redirect_uri).to_hash
|
||||
return result
|
||||
rescue Exception => e
|
||||
raise Educoder::TipException.new(e.message)
|
||||
end
|
||||
end
|
||||
|
||||
def user_info(access_token)
|
||||
request(:get, '/api/users/info.json', {access_token: access_token})
|
||||
end
|
||||
end
|
|
@ -0,0 +1,20 @@
|
|||
module Forum
|
||||
class << self
|
||||
def forum_config
|
||||
forum_config = {}
|
||||
|
||||
begin
|
||||
config = Rails.application.config_for(:configuration).symbolize_keys!
|
||||
forum_config = config[:forum].symbolize_keys!
|
||||
raise 'forum config missing' if forum_config.blank?
|
||||
rescue => ex
|
||||
raise ex if Rails.env.production?
|
||||
|
||||
puts %Q{\033[33m [warning] forum config or configuration.yml missing,
|
||||
please add it or execute 'cp config/configuration.yml.example config/configuration.yml' \033[0m}
|
||||
forum_config = {}
|
||||
end
|
||||
forum_config
|
||||
end
|
||||
end
|
||||
end
|
|
@ -39,6 +39,6 @@ class Gitea::Pull < Gitea::Base
|
|||
|
||||
serialize :conflicted_files, Array
|
||||
|
||||
belongs_to :pull_request, class_name: '::PullRequest', foreign_key: :id, primary_key: :gitea_number, optional: true
|
||||
belongs_to :pull_request, class_name: '::PullRequest', foreign_key: :id, primary_key: :gitea_id, optional: true
|
||||
|
||||
end
|
||||
|
|
|
@ -36,6 +36,7 @@ class MessageTemplate::IssueAssigned < MessageTemplate
|
|||
def self.get_email_message_content(receiver, operator, issue)
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::IssueAssigned"]
|
||||
end
|
||||
project = issue&.project
|
||||
owner = project&.owner
|
||||
title = email_title
|
||||
|
@ -55,9 +56,6 @@ class MessageTemplate::IssueAssigned < MessageTemplate
|
|||
content.gsub!('{id}', issue&.id.to_s)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::IssueAssigned.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -191,6 +191,7 @@ class MessageTemplate::IssueChanged < MessageTemplate
|
|||
return '', '', '' if change_params.blank?
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::IssueChanged"]
|
||||
end
|
||||
project = issue&.project
|
||||
owner = project&.owner
|
||||
title = email_title
|
||||
|
@ -361,10 +362,6 @@ class MessageTemplate::IssueChanged < MessageTemplate
|
|||
end
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::IssueChanged.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -33,6 +33,7 @@ class MessageTemplate::IssueDeleted < MessageTemplate
|
|||
def self.get_email_message_content(receiver, operator, issue_title)
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::IssueChanged"]
|
||||
end
|
||||
title = email_title
|
||||
title.gsub!('{title}', issue_title)
|
||||
content = email
|
||||
|
@ -43,9 +44,6 @@ class MessageTemplate::IssueDeleted < MessageTemplate
|
|||
content.gsub!('{title}', issue_title)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::IssueDeleted.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -34,6 +34,7 @@ class MessageTemplate::OrganizationJoined < MessageTemplate
|
|||
def self.get_email_message_content(receiver, organization)
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Organization"]
|
||||
end
|
||||
title = email_title
|
||||
title.gsub!('{organization}', organization&.real_name)
|
||||
content = email
|
||||
|
@ -43,10 +44,6 @@ class MessageTemplate::OrganizationJoined < MessageTemplate
|
|||
content.gsub!('{organization}', organization&.real_name)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::OrganizationJoined.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -34,6 +34,7 @@ class MessageTemplate::OrganizationLeft < MessageTemplate
|
|||
def self.get_email_message_content(receiver, organization)
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Organization"]
|
||||
end
|
||||
title = email_title
|
||||
title.gsub!('{organization}', organization&.real_name)
|
||||
content = email
|
||||
|
@ -43,10 +44,6 @@ class MessageTemplate::OrganizationLeft < MessageTemplate
|
|||
content.gsub!('{organization}', organization&.real_name)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::OrganizationLeft.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -34,6 +34,7 @@ class MessageTemplate::OrganizationRole < MessageTemplate
|
|||
def self.get_email_message_content(receiver, organization, role)
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Permission"]
|
||||
end
|
||||
title = email_title
|
||||
title.gsub!('{organization}', organization&.real_name)
|
||||
title.gsub!('{role}', role)
|
||||
|
@ -45,10 +46,6 @@ class MessageTemplate::OrganizationRole < MessageTemplate
|
|||
content.gsub!('{role}', role)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::OrganizationRole.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -38,6 +38,7 @@ class MessageTemplate::ProjectIssue < MessageTemplate
|
|||
def self.get_email_message_content(receiver, is_manager, operator, issue)
|
||||
if receiver.user_template_message_setting.present? && is_manager
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["ManageProject::Issue"]
|
||||
end
|
||||
project = issue&.project
|
||||
owner = project&.owner
|
||||
title = email_title
|
||||
|
@ -58,10 +59,6 @@ class MessageTemplate::ProjectIssue < MessageTemplate
|
|||
content.gsub!('{title}', issue&.subject)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::ProjectIssue.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -34,6 +34,7 @@ class MessageTemplate::ProjectJoined < MessageTemplate
|
|||
def self.get_email_message_content(receiver, project)
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Project"]
|
||||
end
|
||||
title = email_title
|
||||
title.gsub!('{repository}', project&.name)
|
||||
|
||||
|
@ -46,10 +47,6 @@ class MessageTemplate::ProjectJoined < MessageTemplate
|
|||
content.gsub!('{repository}', project&.name)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::ProjectJoined.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -33,6 +33,7 @@ class MessageTemplate::ProjectLeft < MessageTemplate
|
|||
def self.get_email_message_content(receiver, project)
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Project"]
|
||||
end
|
||||
title = email_title
|
||||
title.gsub!('{repository}', project&.name)
|
||||
|
||||
|
@ -45,10 +46,6 @@ class MessageTemplate::ProjectLeft < MessageTemplate
|
|||
content.gsub!('{repository}', project&.name)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::ProjectLeft.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -34,6 +34,7 @@ class MessageTemplate::ProjectMemberJoined < MessageTemplate
|
|||
def self.get_email_message_content(receiver, user, project)
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["ManageProject::Member"]
|
||||
end
|
||||
title = email_title
|
||||
title.gsub!('{nickname1}', user&.real_name)
|
||||
title.gsub!('{nickname2}', project&.owner&.real_name)
|
||||
|
@ -50,9 +51,6 @@ class MessageTemplate::ProjectMemberJoined < MessageTemplate
|
|||
content.gsub!('{repository}', project&.name)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::ProjectMemberJoined.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -34,6 +34,7 @@ class MessageTemplate::ProjectMemberLeft < MessageTemplate
|
|||
def self.get_email_message_content(receiver, user, project)
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["ManageProject::Member"]
|
||||
end
|
||||
title = email_title
|
||||
title.gsub!('{nickname1}', user&.real_name)
|
||||
title.gsub!('{nickname2}', project&.owner&.real_name)
|
||||
|
@ -50,10 +51,6 @@ class MessageTemplate::ProjectMemberLeft < MessageTemplate
|
|||
content.gsub!('{repository}', project&.name)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::ProjectMemberLeft.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -38,6 +38,7 @@ class MessageTemplate::ProjectPullRequest < MessageTemplate
|
|||
def self.get_email_message_content(receiver, is_manager, operator, pull_request)
|
||||
if receiver.user_template_message_setting.present? && is_manager
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["ManageProject::PullRequest"]
|
||||
end
|
||||
project = pull_request&.project
|
||||
owner = project&.owner
|
||||
title = email_title
|
||||
|
@ -58,9 +59,6 @@ class MessageTemplate::ProjectPullRequest < MessageTemplate
|
|||
content.gsub!('{title}', pull_request&.title)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::ProjectPullRequest.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -34,6 +34,7 @@ class MessageTemplate::ProjectRole < MessageTemplate
|
|||
def self.get_email_message_content(receiver, project, role)
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Permission"]
|
||||
end
|
||||
title = email_title
|
||||
title.gsub!('{repository}', project&.name)
|
||||
title.gsub!('{role}', role)
|
||||
|
@ -48,10 +49,6 @@ class MessageTemplate::ProjectRole < MessageTemplate
|
|||
content.gsub!('{role}', role)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::ProjectRole.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -159,9 +159,10 @@ class MessageTemplate::ProjectSettingChanged < MessageTemplate
|
|||
end
|
||||
|
||||
def self.get_email_message_content(receiver, operator, project, change_params)
|
||||
return '', '', '' if change_params.blank?
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["ManageProject::SettingChanged"]
|
||||
end
|
||||
return '', '', '' if change_params.blank?
|
||||
owner = project&.owner
|
||||
title = email_title
|
||||
title.gsub!('{nickname2}', owner&.real_name)
|
||||
|
@ -302,9 +303,6 @@ class MessageTemplate::ProjectSettingChanged < MessageTemplate
|
|||
end
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::ProjectSettingChanged.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -36,6 +36,7 @@ class MessageTemplate::PullRequestAssigned < MessageTemplate
|
|||
def self.get_email_message_content(receiver, operator, pull_request)
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::PullRequestAssigned"]
|
||||
end
|
||||
project = pull_request&.project
|
||||
owner = project&.owner
|
||||
title = email_title
|
||||
|
@ -55,9 +56,6 @@ class MessageTemplate::PullRequestAssigned < MessageTemplate
|
|||
content.gsub!('{id}', pull_request&.id.to_s)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::PullRequestAssigned.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -103,6 +103,7 @@ class MessageTemplate::PullRequestChanged < MessageTemplate
|
|||
return '', '', '' if change_params.blank?
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::PullRequestChanged"]
|
||||
end
|
||||
project = pull_request&.project
|
||||
owner = project&.owner
|
||||
title = email_title
|
||||
|
@ -185,10 +186,6 @@ class MessageTemplate::PullRequestChanged < MessageTemplate
|
|||
end
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::PullRequestChanged.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -36,6 +36,7 @@ class MessageTemplate::PullRequestClosed < MessageTemplate
|
|||
def self.get_email_message_content(receiver, operator, pull_request)
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::PullRequestChanged"]
|
||||
end
|
||||
project = pull_request&.project
|
||||
owner = project&.owner
|
||||
title = email_title
|
||||
|
@ -53,10 +54,6 @@ class MessageTemplate::PullRequestClosed < MessageTemplate
|
|||
content.gsub!('{id}', pull_request&.id.to_s)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::PullRequestClosed.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -36,6 +36,7 @@ class MessageTemplate::PullRequestMerged < MessageTemplate
|
|||
def self.get_email_message_content(receiver, operator, pull_request)
|
||||
if receiver.user_template_message_setting.present?
|
||||
return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::PullRequestChanged"]
|
||||
end
|
||||
project = pull_request&.project
|
||||
owner = project&.owner
|
||||
title = email_title
|
||||
|
@ -53,9 +54,6 @@ class MessageTemplate::PullRequestMerged < MessageTemplate
|
|||
content.gsub!('{id}', pull_request&.id.to_s)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::PullRequestMerged.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: projects
|
||||
|
@ -38,8 +37,6 @@
|
|||
# rep_identifier :string(255)
|
||||
# project_category_id :integer
|
||||
# project_language_id :integer
|
||||
# license_id :integer
|
||||
# ignore_id :integer
|
||||
# praises_count :integer default("0")
|
||||
# watchers_count :integer default("0")
|
||||
# issues_count :integer default("0")
|
||||
|
@ -53,6 +50,8 @@
|
|||
# open_devops_count :integer default("0")
|
||||
# recommend :boolean default("0")
|
||||
# platform :integer default("0")
|
||||
# license_id :integer
|
||||
# ignore_id :integer
|
||||
# default_branch :string(255) default("master")
|
||||
# website :string(255)
|
||||
# lesson_url :string(255)
|
||||
|
|
|
@ -37,7 +37,7 @@ class PullRequest < ApplicationRecord
|
|||
has_many :pull_request_tags, foreign_key: :pull_request_id
|
||||
has_many :project_trends, as: :trend, dependent: :destroy
|
||||
has_many :attachments, as: :container, dependent: :destroy
|
||||
has_one :gitea_pull, foreign_key: :id, primary_key: :gitea_number, class_name: 'Gitea::Pull'
|
||||
has_one :gitea_pull, foreign_key: :id, primary_key: :gitea_id, class_name: 'Gitea::Pull'
|
||||
|
||||
scope :merged_and_closed, ->{where.not(status: 0)}
|
||||
scope :opening, -> {where(status: 0)}
|
||||
|
|
|
@ -65,7 +65,7 @@ class Site < ApplicationRecord
|
|||
commons = [
|
||||
{name: '通知', key: 'notice', url: '/users/current_user/user_messages'},
|
||||
{name: '找回密码', key: 'lost_password', url: '/account/lost_password'},
|
||||
{name: '注册', key: 'register', url: '/login?login=false'}
|
||||
{name: '注册', key: 'register', url: '/register'}
|
||||
]
|
||||
|
||||
commons.each { |ele|
|
||||
|
|
|
@ -76,7 +76,7 @@ class Token < ActiveRecord::Base
|
|||
# Returns the active user who owns the key for the given action
|
||||
def self.find_active_user(action, key, validity_days=nil)
|
||||
user = find_user(action, key, validity_days)
|
||||
if user && user.active?
|
||||
if user && (user.active? || user.need_edit_info?)
|
||||
user
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: topics
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# title :string(255)
|
||||
# uuid :integer
|
||||
# image_url :string(255)
|
||||
# url :string(255)
|
||||
# order_index :integer
|
||||
#
|
||||
|
||||
class Topic < ApplicationRecord
|
||||
|
||||
default_scope { order(order_index: :desc)}
|
||||
|
||||
scope :with_single_type, ->(type){where(type: trans_simpletype_to_classtype(type))}
|
||||
|
||||
def image
|
||||
image_url('image')
|
||||
end
|
||||
|
||||
def self.trans_simpletype_to_classtype(type)
|
||||
case type
|
||||
when 'activity_forum'
|
||||
'Topic::ActivityForum'
|
||||
when 'banner'
|
||||
'Topic::Banner'
|
||||
when 'card'
|
||||
'Topic::Card'
|
||||
when 'cooperator'
|
||||
'Topic::Cooperator'
|
||||
when 'excellent_project'
|
||||
'Topic::ExcellentProject'
|
||||
when 'experience_forum'
|
||||
'Topic::ExperienceForum'
|
||||
when 'pinned_forum'
|
||||
'Topic::PinnedForum'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def image_url(type)
|
||||
return nil unless Util::FileManage.exists?(self, type)
|
||||
Util::FileManage.source_disk_file_url(self, type)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: topics
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# title :string(255)
|
||||
# uuid :integer
|
||||
# image_url :string(255)
|
||||
# url :string(255)
|
||||
# order_index :integer
|
||||
#
|
||||
|
||||
# 首页平台动态
|
||||
class Topic::ActivityForum < Topic
|
||||
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: topics
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# title :string(255)
|
||||
# uuid :integer
|
||||
# image_url :string(255)
|
||||
# url :string(255)
|
||||
# order_index :integer
|
||||
#
|
||||
|
||||
# 首页banner
|
||||
class Topic::Banner < Topic
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: topics
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# title :string(255)
|
||||
# uuid :integer
|
||||
# image_url :string(255)
|
||||
# url :string(255)
|
||||
# order_index :integer
|
||||
#
|
||||
|
||||
# 首页卡片内容
|
||||
class Topic::Card < Topic
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: topics
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# title :string(255)
|
||||
# uuid :integer
|
||||
# image_url :string(255)
|
||||
# url :string(255)
|
||||
# order_index :integer
|
||||
#
|
||||
|
||||
# 首页合作伙伴
|
||||
class Topic::Cooperator < Topic
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: topics
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# title :string(255)
|
||||
# uuid :integer
|
||||
# image_url :string(255)
|
||||
# url :string(255)
|
||||
# order_index :integer
|
||||
#
|
||||
|
||||
# 首页优秀项目
|
||||
class Topic::ExcellentProject < Topic
|
||||
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: topics
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# title :string(255)
|
||||
# uuid :integer
|
||||
# image_url :string(255)
|
||||
# url :string(255)
|
||||
# order_index :integer
|
||||
#
|
||||
|
||||
# 首页经验分享
|
||||
class Topic::ExperienceForum < Topic
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: topics
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# title :string(255)
|
||||
# uuid :integer
|
||||
# image_url :string(255)
|
||||
# url :string(255)
|
||||
# order_index :integer
|
||||
#
|
||||
|
||||
# 首页精选文章
|
||||
class Topic::PinnedForum < Topic
|
||||
end
|
|
@ -83,6 +83,7 @@ class User < Owner
|
|||
STATUS_ACTIVE = 1
|
||||
STATUS_REGISTERED = 2
|
||||
STATUS_LOCKED = 3
|
||||
STATUS_EDIT_INFO = 4
|
||||
|
||||
# tpi tpm权限控制
|
||||
EDU_ADMIN = 1 # 超级管理员
|
||||
|
@ -175,7 +176,7 @@ class User < Owner
|
|||
has_many :system_notifications, through: :system_notification_histories
|
||||
|
||||
# Groups and active users
|
||||
scope :active, lambda { where(status: STATUS_ACTIVE) }
|
||||
scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) }
|
||||
scope :like, lambda { |keywords|
|
||||
sql = "CONCAT(lastname, firstname) LIKE :search OR nickname LIKE :search OR login LIKE :search OR mail LIKE :search OR nickname LIKE :search"
|
||||
where(sql, :search => "%#{keywords.split(" ").join('|')}%") unless keywords.blank?
|
||||
|
@ -418,6 +419,10 @@ class User < Owner
|
|||
status == STATUS_LOCKED
|
||||
end
|
||||
|
||||
def need_edit_info?
|
||||
status == STATUS_EDIT_INFO
|
||||
end
|
||||
|
||||
def activate
|
||||
self.status = STATUS_ACTIVE
|
||||
end
|
||||
|
@ -430,6 +435,10 @@ class User < Owner
|
|||
self.status = STATUS_LOCKED
|
||||
end
|
||||
|
||||
def need_edit_info
|
||||
self.status = STATUS_EDIT_INFO
|
||||
end
|
||||
|
||||
def activate!
|
||||
update_attribute(:status, STATUS_ACTIVE)
|
||||
prohibit_gitea_user_login!(false)
|
||||
|
@ -449,6 +458,10 @@ class User < Owner
|
|||
{email: self.mail, prohibit_login: prohibit_login})
|
||||
end
|
||||
|
||||
def need_edit_info!
|
||||
update_attribute(:status, STATUS_EDIT_INFO)
|
||||
end
|
||||
|
||||
# 课程用户身份
|
||||
def course_identity(course)
|
||||
if !logged?
|
||||
|
|
|
@ -44,17 +44,17 @@ class UserTemplateMessageSetting < ApplicationRecord
|
|||
|
||||
def self.init_email_body
|
||||
{
|
||||
"Normal::Permission": false,
|
||||
"Normal::Project": false,
|
||||
"Normal::Organization": false,
|
||||
"Normal::IssueAssigned": false,
|
||||
"Normal::PullRequestAssigned": false,
|
||||
"CreateOrAssign::IssueChanged": false,
|
||||
"CreateOrAssign::PullRequestChanged": false,
|
||||
"ManageProject::Issue": false,
|
||||
"ManageProject::PullRequest": false,
|
||||
"ManageProject::Member": false,
|
||||
"ManageProject::SettingChanged": false,
|
||||
"Normal::Permission": true,
|
||||
"Normal::Project": true,
|
||||
"Normal::Organization": true,
|
||||
"Normal::IssueAssigned": true,
|
||||
"Normal::PullRequestAssigned": true,
|
||||
"CreateOrAssign::IssueChanged": true,
|
||||
"CreateOrAssign::PullRequestChanged": true,
|
||||
"ManageProject::Issue": true,
|
||||
"ManageProject::PullRequest": true,
|
||||
"ManageProject::Member": true,
|
||||
"ManageProject::SettingChanged": true,
|
||||
}.stringify_keys!
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
module Accounts
|
||||
class ResetPasswordService < ApplicationService
|
||||
# login、code、password、password_confirmation
|
||||
def initialize(user, params)
|
||||
@user = user
|
||||
@password = params[:password]
|
||||
@password_confirmation = params[:password_confirmation]
|
||||
end
|
||||
|
||||
def call
|
||||
return if @user.blank?
|
||||
password = strip(@password)
|
||||
password_confirmation = strip(@password_confirmation)
|
||||
|
||||
Rails.logger.info "Accounts::ResetPasswordService params:
|
||||
##### password: #{@password} password_confirmation: #{@password_confirmation}"
|
||||
|
||||
@user.password, @user.password_confirmation = password, password_confirmation
|
||||
|
||||
sync_params = {
|
||||
password: password,
|
||||
email: @user.mail
|
||||
}
|
||||
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
|
||||
raise ActiveRecord::Rollback unless interactor.success?
|
||||
|
||||
@user
|
||||
end
|
||||
end
|
||||
end
|
|
@ -18,4 +18,9 @@ class ApplicationService
|
|||
def str_to_boolean str
|
||||
ActiveModel::Type::Boolean.new.cast str
|
||||
end
|
||||
|
||||
def phone_mail_type value
|
||||
value =~ /^1\d{10}$/ ? 1 : 0
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -196,7 +196,6 @@ class Cache::V2::ProjectCommonService < ApplicationService
|
|||
|
||||
def reset_project_common
|
||||
load_project
|
||||
return unless @project.present?
|
||||
return unless @project.is_full_public
|
||||
$redis_cache.del(project_common_key)
|
||||
reset_project_owner_id
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
class Forum::ClientService < ApplicationService
|
||||
attr_reader :url, :params
|
||||
|
||||
PAGINATE_DEFAULT_PAGE = 1
|
||||
PAGINATE_DEFAULT_LIMIT = 20
|
||||
|
||||
def initialize(options={})
|
||||
@url = options[:url]
|
||||
@params = options[:params]
|
||||
end
|
||||
|
||||
def get(url, params={})
|
||||
conn(params).get do |req|
|
||||
req.url full_url(url, 'get')
|
||||
params.except(:token).each_pair do |key, value|
|
||||
req.params["#{key}"] = value
|
||||
end
|
||||
end
|
||||
|
||||
# response.headers.each do |k,v|
|
||||
# puts "#{k}:#{v}"
|
||||
# end #=> 响应头
|
||||
end
|
||||
|
||||
private
|
||||
def conn(auth={})
|
||||
@client ||= begin
|
||||
Faraday.new(url: domain) do |req|
|
||||
req.request :url_encoded
|
||||
req.headers['Content-Type'] = 'application/json'
|
||||
req.response :logger # 显示日志
|
||||
req.adapter Faraday.default_adapter
|
||||
end
|
||||
end
|
||||
@client
|
||||
end
|
||||
|
||||
def base_url
|
||||
Forum.forum_config[:base_url]
|
||||
end
|
||||
|
||||
def domain
|
||||
Forum.forum_config[:domain]
|
||||
end
|
||||
|
||||
def api_url
|
||||
[domain, base_url].join('')
|
||||
end
|
||||
|
||||
def full_url(api_rest, action='post')
|
||||
url = [api_url, api_rest].join('').freeze
|
||||
url = action === 'get' ? url : URI.escape(url)
|
||||
url = URI.escape(url) unless url.ascii_only?
|
||||
puts "[forum] request url: #{url}"
|
||||
return url
|
||||
end
|
||||
|
||||
def render_response(response)
|
||||
status = response.status
|
||||
body = response&.body
|
||||
|
||||
# log_error(status, body)
|
||||
|
||||
body, message = get_body_by_status(status, body)
|
||||
|
||||
[status, message, body]
|
||||
end
|
||||
|
||||
def get_body_by_status(status, body)
|
||||
body, message =
|
||||
case status
|
||||
when 401 then [nil, "401"]
|
||||
when 404 then [nil, "404"]
|
||||
when 403 then [nil, "403"]
|
||||
when 500 then [nil, "500"]
|
||||
else
|
||||
if body.present?
|
||||
body = JSON.parse(body)
|
||||
fix_body(body)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
[body, message]
|
||||
end
|
||||
|
||||
def fix_body(body)
|
||||
return [body, nil] if body.is_a?(Array) || body.is_a?(Hash)
|
||||
|
||||
body['message'].blank? ? [body, nil] : [nil, body['message']]
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
class Forum::Memos::GetService < Forum::ClientService
|
||||
attr_reader :memo_id
|
||||
|
||||
def initialize(memo_id)
|
||||
@memo_id = memo_id
|
||||
end
|
||||
|
||||
def call
|
||||
response = get(url)
|
||||
code, message, body = render_response(response)
|
||||
if code == 200 && body["status"] == 0
|
||||
return body
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def url
|
||||
"/memos/#{memo_id}.json".freeze
|
||||
end
|
||||
end
|
|
@ -12,7 +12,8 @@ class Users::RegisterService < ApplicationService
|
|||
namespace = strip(@namespace)
|
||||
password = strip(@password)
|
||||
|
||||
Rails.logger.info "Users::RegisterService params: ##### #{params} "
|
||||
Rails.logger.info "Users::RegisterService params:
|
||||
##### code: #{code} login: #{login} namespace: #{namespace} password: #{password} "
|
||||
|
||||
email, phone =
|
||||
if register_type == 1
|
||||
|
@ -50,9 +51,4 @@ class Users::RegisterService < ApplicationService
|
|||
def register_type
|
||||
phone_mail_type(@login)
|
||||
end
|
||||
|
||||
def phone_mail_type value
|
||||
value =~ /^1\d{10}$/ ? 1 : 0
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -31,6 +31,17 @@
|
|||
|
||||
<li><%= sidebar_item(admins_reversed_keywords_path, '系统保留关键词', icon: 'key', controller: 'admins-reversed_keywords') %></li>
|
||||
<li><%= sidebar_item(admins_laboratories_path, '云上实验室', icon: 'cloud', controller: 'admins-laboratories') %></li>
|
||||
<li>
|
||||
<%= sidebar_item_group('#setting-index', '首页配置', icon: 'file') do %>
|
||||
<li><%= sidebar_item(admins_topic_banners_path, 'banner管理', icon: 'image', controller: 'admins-topic-banners') %></li>
|
||||
<li><%= sidebar_item(admins_topic_cards_path, '卡片管理', icon: 'archive', controller: 'admins-topic-cards') %></li>
|
||||
<li><%= sidebar_item(admins_topic_activity_forums_path, '平台动态管理', icon: 'bell', controller: 'admins-topic-activity_forums') %></li>
|
||||
<li><%= sidebar_item(admins_topic_excellent_projects_path, '优秀仓库管理', icon: 'git', controller: 'admins-topic-excellent_projects') %></li>
|
||||
<li><%= sidebar_item(admins_topic_pinned_forums_path, '精选文章管理', icon: 'edit', controller: 'admins-topic-pinned_forums') %></li>
|
||||
<li><%= sidebar_item(admins_topic_experience_forums_path, '经验分享管理', icon: 'edit', controller: 'admins-topic-experience_forums') %></li>
|
||||
<li><%= sidebar_item(admins_topic_cooperators_path, '合作伙伴管理', icon: 'user', controller: 'admins-topic-cooperators') %></li>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<%= sidebar_item_group('#setting-submenu', '网站建设', icon: 'cogs') do %>
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<div class="modal fade activity-forum-change-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><%= type == "create" ? "新增" : "编辑" %></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<%= form_for @activity_forum, url: {controller: "topic/activity_forums", action: "#{type}"} do |p| %>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>
|
||||
标题 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :title,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
跳转地址 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :url,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
帖子ID <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :uuid,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
排序等级
|
||||
</label>
|
||||
<%= p.number_field :order_index, class: "form-control",placeholder: ""%>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,33 @@
|
|||
<table class="table table-hover text-center subject-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="5%">序号</th>
|
||||
<th width="20%">标题</th>
|
||||
<th width="20%">跳转地址</th>
|
||||
<th width="10%">帖子ID</th>
|
||||
<th width="20%">排序等级</th>
|
||||
<th width="25%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if activity_forums.present? %>
|
||||
<% activity_forums.each_with_index do |activity_forum, index| %>
|
||||
<tr class="activity-forum-item-<%= activity_forum.id %>">
|
||||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td><%= activity_forum.title %></td>
|
||||
<td><%= activity_forum.url %></td>
|
||||
<td><%= activity_forum.uuid %></td>
|
||||
<td><%= activity_forum.order_index %></td>
|
||||
<td class="action-container">
|
||||
<%= link_to "编辑", edit_admins_topic_activity_forum_path(activity_forum), remote: true, class: "action" %>
|
||||
<%= link_to "删除", admins_topic_activity_forum_path(activity_forum), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render 'admins/shared/no_data_for_table' %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= render partial: 'admins/shared/paginate', locals: { objects: activity_forums } %>
|
|
@ -0,0 +1,2 @@
|
|||
$("#activity-forum-modals").html("<%= j render(partial: 'admins/topic/activity_forums/form_modal', locals: {type: 'update'}) %>")
|
||||
$(".activity-forum-change-modal").modal('show');
|
|
@ -0,0 +1,18 @@
|
|||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('平台动态管理') %>
|
||||
<% end %>
|
||||
|
||||
<div class="box search-form-container project-list-form">
|
||||
<%= form_tag(admins_topic_activity_forums_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
|
||||
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '标题检索') %>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
|
||||
<% end %>
|
||||
<%= link_to "新增", new_admins_topic_activity_forum_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
|
||||
</div>
|
||||
|
||||
<div class="box admin-list-container activity-forum-list-container">
|
||||
<%= render partial: 'admins/topic/activity_forums/list', locals: { activity_forums: @activity_forums } %>
|
||||
</div>
|
||||
<div id="activity-forum-modals">
|
||||
</div>
|
|
@ -0,0 +1 @@
|
|||
$('.activity-forum-list-container').html("<%= j( render partial: 'admins/topic/activity_forums/list', locals: { activity_forums: @activity_forums } ) %>");
|
|
@ -0,0 +1,2 @@
|
|||
$("#activity-forum-modals").html("<%= j render(partial: 'admins/topic/activity_forums/form_modal', locals: {type: 'create'}) %>")
|
||||
$(".activity-forum-change-modal").modal('show');
|
|
@ -0,0 +1,45 @@
|
|||
<div class="modal fade banner-change-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><%= type == "create" ? "新增" : "编辑" %></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<%= form_for @banner, url: {controller: "topic/banners", action: "#{type}"}, html: { enctype: 'multipart/form-data' } do |p| %>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>
|
||||
标题 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :title,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
排序等级
|
||||
</label>
|
||||
<%= p.number_field :order_index, class: "form-control",placeholder: ""%>
|
||||
</div>
|
||||
<div class="logo-item">
|
||||
<% logo_img = @banner.image %>
|
||||
<div class="logo-item-left mr-3 <%= logo_img ? 'has-img' : '' %>">
|
||||
<img class="logo-item-img nav-logo-img" src="<%= logo_img %>" style="<%= logo_img.present? ? '' : 'display: none' %>"/>
|
||||
<%= file_field_tag(:image, accept: 'image/png,image/jpg,image/jpeg',style: "display: none", value: params[:image]) %>
|
||||
<label for="image" class="logo-item-upload" data-toggle="tooltip" data-title="选择图片"></label>
|
||||
</div>
|
||||
<div class="logo-item-right">
|
||||
<div class="logo-item-title flex-1">logo</div>
|
||||
<div>格式:PNG、JPG</div>
|
||||
<div>尺寸:高度38px以内,宽等比例缩放</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,31 @@
|
|||
<table class="table table-hover text-center subject-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="5%">序号</th>
|
||||
<th width="20%">标题</th>
|
||||
<th width="20%">图片</th>
|
||||
<th width="20%">排序等级</th>
|
||||
<th width="25%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if banners.present? %>
|
||||
<% banners.each_with_index do |banner, index| %>
|
||||
<tr class="banner-item-<%= banner.id %>">
|
||||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td><%= banner.title %></td>
|
||||
<td><img style="width:150px" src="<%= banner.image %>" /></td>
|
||||
<td><%= banner.order_index %></td>
|
||||
<td class="action-container">
|
||||
<%= link_to "编辑", edit_admins_topic_banner_path(banner), remote: true, class: "action" %>
|
||||
<%= link_to "删除", admins_topic_banner_path(banner), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render 'admins/shared/no_data_for_table' %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= render partial: 'admins/shared/paginate', locals: { objects: banners } %>
|
|
@ -0,0 +1,18 @@
|
|||
$("#banner-modals").html("<%= j render(partial: 'admins/topic/banners/form_modal', locals: {type: 'update'}) %>")
|
||||
$(".banner-change-modal").modal('show');
|
||||
|
||||
$('.logo-item-left').on("change", 'input[type="file"]', function () {
|
||||
var $fileInput = $(this);
|
||||
var file = this.files[0];
|
||||
var imageType = /image.*/;
|
||||
if (file && file.type.match(imageType)) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function () {
|
||||
var $box = $fileInput.parent();
|
||||
$box.find('img').attr('src', reader.result).css('display', 'block');
|
||||
$box.addClass('has-img');
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
} else {
|
||||
}
|
||||
});
|
|
@ -0,0 +1,18 @@
|
|||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('卡片管理') %>
|
||||
<% end %>
|
||||
|
||||
<div class="box search-form-container project-list-form">
|
||||
<%= form_tag(admins_topic_banners_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
|
||||
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '标题检索') %>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
|
||||
<% end %>
|
||||
<%= link_to "新增", new_admins_topic_banner_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
|
||||
</div>
|
||||
|
||||
<div class="box admin-list-container banner-list-container">
|
||||
<%= render partial: 'admins/topic/banners/list', locals: { banners: @banners } %>
|
||||
</div>
|
||||
<div id="banner-modals">
|
||||
</div>
|
|
@ -0,0 +1 @@
|
|||
$('.banner-list-container').html("<%= j( render partial: 'admins/topic/banners/list', locals: { banners: @banners } ) %>");
|
|
@ -0,0 +1,18 @@
|
|||
$("#banner-modals").html("<%= j render(partial: 'admins/topic/banners/form_modal', locals: {type: 'create'}) %>")
|
||||
$(".banner-change-modal").modal('show');
|
||||
|
||||
$('.logo-item-left').on("change", 'input[type="file"]', function () {
|
||||
var $fileInput = $(this);
|
||||
var file = this.files[0];
|
||||
var imageType = /image.*/;
|
||||
if (file && file.type.match(imageType)) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function () {
|
||||
var $box = $fileInput.parent();
|
||||
$box.find('img').attr('src', reader.result).css('display', 'block');
|
||||
$box.addClass('has-img');
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
} else {
|
||||
}
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
<div class="modal fade card-change-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><%= type == "create" ? "新增" : "编辑" %></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<%= form_for @card, url: {controller: "topic/cards", action: "#{type}"} do |p| %>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>
|
||||
标题 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :title,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
跳转地址 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :url,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
排序等级
|
||||
</label>
|
||||
<%= p.number_field :order_index, class: "form-control",placeholder: ""%>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,31 @@
|
|||
<table class="table table-hover text-center subject-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="5%">序号</th>
|
||||
<th width="20%">标题</th>
|
||||
<th width="20%">跳转地址</th>
|
||||
<th width="20%">排序等级</th>
|
||||
<th width="25%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if cards.present? %>
|
||||
<% cards.each_with_index do |card, index| %>
|
||||
<tr class="card-item-<%= card.id %>">
|
||||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td><%= card.title %></td>
|
||||
<td><%= card.url %></td>
|
||||
<td><%= card.order_index %></td>
|
||||
<td class="action-container">
|
||||
<%= link_to "编辑", edit_admins_topic_card_path(card), remote: true, class: "action" %>
|
||||
<%= link_to "删除", admins_topic_card_path(card), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render 'admins/shared/no_data_for_table' %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= render partial: 'admins/shared/paginate', locals: { objects: cards } %>
|
|
@ -0,0 +1,2 @@
|
|||
$("#card-modals").html("<%= j render(partial: 'admins/topic/cards/form_modal', locals: {type: 'update'}) %>")
|
||||
$(".card-change-modal").modal('show');
|
|
@ -0,0 +1,18 @@
|
|||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('卡片管理') %>
|
||||
<% end %>
|
||||
|
||||
<div class="box search-form-container project-list-form">
|
||||
<%= form_tag(admins_topic_cards_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
|
||||
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '标题检索') %>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
|
||||
<% end %>
|
||||
<%= link_to "新增", new_admins_topic_card_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
|
||||
</div>
|
||||
|
||||
<div class="box admin-list-container card-list-container">
|
||||
<%= render partial: 'admins/topic/cards/list', locals: { cards: @cards } %>
|
||||
</div>
|
||||
<div id="card-modals">
|
||||
</div>
|
|
@ -0,0 +1 @@
|
|||
$('.card-list-container').html("<%= j( render partial: 'admins/topic/cards/list', locals: { cards: @cards } ) %>");
|
|
@ -0,0 +1,2 @@
|
|||
$("#card-modals").html("<%= j render(partial: 'admins/topic/cards/form_modal', locals: {type: 'create'}) %>")
|
||||
$(".card-change-modal").modal('show');
|
|
@ -0,0 +1,51 @@
|
|||
<div class="modal fade cooperator-change-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><%= type == "create" ? "新增" : "编辑" %></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<%= form_for @cooperator, url: {controller: "topic/cooperators", action: "#{type}"}, html: { enctype: 'multipart/form-data' } do |p| %>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>
|
||||
标题 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :title,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
跳转地址 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :url,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
排序等级
|
||||
</label>
|
||||
<%= p.number_field :order_index, class: "form-control",placeholder: ""%>
|
||||
</div>
|
||||
<div class="logo-item">
|
||||
<% logo_img = @cooperator.image %>
|
||||
<div class="logo-item-left mr-3 <%= logo_img ? 'has-img' : '' %>">
|
||||
<img class="logo-item-img nav-logo-img" src="<%= logo_img %>" style="<%= logo_img.present? ? '' : 'display: none' %>"/>
|
||||
<%= file_field_tag(:image, accept: 'image/png,image/jpg,image/jpeg',style: "display: none", value: params[:image]) %>
|
||||
<label for="image" class="logo-item-upload" data-toggle="tooltip" data-title="选择图片"></label>
|
||||
</div>
|
||||
<div class="logo-item-right">
|
||||
<div class="logo-item-title flex-1">logo</div>
|
||||
<div>格式:PNG、JPG</div>
|
||||
<div>尺寸:高度38px以内,宽等比例缩放</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,33 @@
|
|||
<table class="table table-hover text-center subject-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="5%">序号</th>
|
||||
<th width="20%">标题</th>
|
||||
<th width="20%">跳转地址</th>
|
||||
<th width="20%">图片</th>
|
||||
<th width="20%">排序等级</th>
|
||||
<th width="25%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if cooperators.present? %>
|
||||
<% cooperators.each_with_index do |cooperator, index| %>
|
||||
<tr class="cooperator-item-<%= cooperator.id %>">
|
||||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td><%= cooperator.title %></td>
|
||||
<td><%= cooperator.url %></td>
|
||||
<td><img style="width:150px" src="<%= cooperator.image %>" /></td>
|
||||
<td><%= cooperator.order_index %></td>
|
||||
<td class="action-container">
|
||||
<%= link_to "编辑", edit_admins_topic_cooperator_path(cooperator), remote: true, class: "action" %>
|
||||
<%= link_to "删除", admins_topic_cooperator_path(cooperator), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render 'admins/shared/no_data_for_table' %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= render partial: 'admins/shared/paginate', locals: { objects: cooperators } %>
|
|
@ -0,0 +1,18 @@
|
|||
$("#cooperator-modals").html("<%= j render(partial: 'admins/topic/cooperators/form_modal', locals: {type: 'update'}) %>")
|
||||
$(".cooperator-change-modal").modal('show');
|
||||
|
||||
$('.logo-item-left').on("change", 'input[type="file"]', function () {
|
||||
var $fileInput = $(this);
|
||||
var file = this.files[0];
|
||||
var imageType = /image.*/;
|
||||
if (file && file.type.match(imageType)) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function () {
|
||||
var $box = $fileInput.parent();
|
||||
$box.find('img').attr('src', reader.result).css('display', 'block');
|
||||
$box.addClass('has-img');
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
} else {
|
||||
}
|
||||
});
|
|
@ -0,0 +1,18 @@
|
|||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('卡片管理') %>
|
||||
<% end %>
|
||||
|
||||
<div class="box search-form-container project-list-form">
|
||||
<%= form_tag(admins_topic_cooperators_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
|
||||
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '标题检索') %>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
|
||||
<% end %>
|
||||
<%= link_to "新增", new_admins_topic_cooperator_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
|
||||
</div>
|
||||
|
||||
<div class="box admin-list-container cooperator-list-container">
|
||||
<%= render partial: 'admins/topic/cooperators/list', locals: { cooperators: @cooperators } %>
|
||||
</div>
|
||||
<div id="cooperator-modals">
|
||||
</div>
|
|
@ -0,0 +1 @@
|
|||
$('.cooperator-list-container').html("<%= j( render partial: 'admins/topic/cooperators/list', locals: { cooperators: @cooperators } ) %>");
|
|
@ -0,0 +1,18 @@
|
|||
$("#cooperator-modals").html("<%= j render(partial: 'admins/topic/cooperators/form_modal', locals: {type: 'create'}) %>")
|
||||
$(".cooperator-change-modal").modal('show');
|
||||
|
||||
$('.logo-item-left').on("change", 'input[type="file"]', function () {
|
||||
var $fileInput = $(this);
|
||||
var file = this.files[0];
|
||||
var imageType = /image.*/;
|
||||
if (file && file.type.match(imageType)) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function () {
|
||||
var $box = $fileInput.parent();
|
||||
$box.find('img').attr('src', reader.result).css('display', 'block');
|
||||
$box.addClass('has-img');
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
} else {
|
||||
}
|
||||
});
|
|
@ -0,0 +1,44 @@
|
|||
<div class="modal fade excellent-project-change-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><%= type == "create" ? "新增" : "编辑" %></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<%= form_for @excellent_project, url: {controller: "topic/excellent_projects", action: "#{type}"} do |p| %>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>
|
||||
标题 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :title,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
跳转地址 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :url,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
项目ID <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.number_field :uuid,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
排序等级
|
||||
</label>
|
||||
<%= p.number_field :order_index, class: "form-control",placeholder: ""%>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,33 @@
|
|||
<table class="table table-hover text-center subject-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="5%">序号</th>
|
||||
<th width="20%">标题</th>
|
||||
<th width="20%">跳转地址</th>
|
||||
<th width="10%">项目ID</th>
|
||||
<th width="20%">排序等级</th>
|
||||
<th width="25%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if excellent_projects.present? %>
|
||||
<% excellent_projects.each_with_index do |excellent_project, index| %>
|
||||
<tr class="excellent-project-item-<%= excellent_project.id %>">
|
||||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td><%= excellent_project.title %></td>
|
||||
<td><%= excellent_project.url %></td>
|
||||
<td><%= excellent_project.uuid %></td>
|
||||
<td><%= excellent_project.order_index %></td>
|
||||
<td class="action-container">
|
||||
<%= link_to "编辑", edit_admins_topic_excellent_project_path(excellent_project), remote: true, class: "action" %>
|
||||
<%= link_to "删除", admins_topic_excellent_project_path(excellent_project), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render 'admins/shared/no_data_for_table' %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= render partial: 'admins/shared/paginate', locals: { objects: excellent_projects } %>
|
|
@ -0,0 +1,2 @@
|
|||
$("#excellent-project-modals").html("<%= j render(partial: 'admins/topic/excellent_projects/form_modal', locals: {type: 'update'}) %>")
|
||||
$(".excellent-project-change-modal").modal('show');
|
|
@ -0,0 +1,18 @@
|
|||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('优秀仓库管理') %>
|
||||
<% end %>
|
||||
|
||||
<div class="box search-form-container project-list-form">
|
||||
<%= form_tag(admins_topic_excellent_projects_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
|
||||
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '标题检索') %>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
|
||||
<% end %>
|
||||
<%= link_to "新增", new_admins_topic_excellent_project_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
|
||||
</div>
|
||||
|
||||
<div class="box admin-list-container excellent-project-list-container">
|
||||
<%= render partial: 'admins/topic/excellent_projects/list', locals: { excellent_projects: @excellent_projects } %>
|
||||
</div>
|
||||
<div id="excellent-project-modals">
|
||||
</div>
|
|
@ -0,0 +1 @@
|
|||
$('.excellent-project-list-container').html("<%= j( render partial: 'admins/topic/excellent_projects/list', locals: { excellent_projects: @excellent_projects } ) %>");
|
|
@ -0,0 +1,2 @@
|
|||
$("#excellent-project-modals").html("<%= j render(partial: 'admins/topic/excellent_projects/form_modal', locals: {type: 'create'}) %>")
|
||||
$(".excellent-project-change-modal").modal('show');
|
|
@ -0,0 +1,44 @@
|
|||
<div class="modal fade experience-forum-change-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><%= type == "create" ? "新增" : "编辑" %></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<%= form_for @experience_forum, url: {controller: "topic/experience_forums", action: "#{type}"} do |p| %>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>
|
||||
标题 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :title,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
跳转地址 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :url,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
帖子ID <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.number_field :uuid,class: "form-control input-lg",required: true%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
排序等级
|
||||
</label>
|
||||
<%= p.number_field :order_index, class: "form-control",placeholder: ""%>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue