新增:openkylin_sign 签署协议
This commit is contained in:
parent
4dbb416143
commit
e9da21bccf
|
@ -0,0 +1,23 @@
|
||||||
|
class Api::V1::Users::OpenkylinSignController < Api::V1::BaseController
|
||||||
|
|
||||||
|
before_action :load_observe_user
|
||||||
|
|
||||||
|
def competitions
|
||||||
|
@competition_ids = EduSetting.get("openkylin_sign_competitions").split(",") rescue []
|
||||||
|
render :json => {data: @competition_ids}
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@object_result = Api::V1::Users::OpenkylinSign::CreateService.call(@observe_user, create_params)
|
||||||
|
if @result_object
|
||||||
|
return render_ok
|
||||||
|
else
|
||||||
|
return render_error('签署失败!')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def create_params
|
||||||
|
params.permit(:login, :email, :nickname, :phone, :address)
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,7 +1,7 @@
|
||||||
class Api::V1::UsersController < Api::V1::BaseController
|
class Api::V1::UsersController < Api::V1::BaseController
|
||||||
|
|
||||||
before_action :load_observe_user, except: [:check_user_id]
|
before_action :load_observe_user, except: [:check_user_id, :check_user_login]
|
||||||
before_action :check_auth_for_observe_user, except: [:check_user_id]
|
before_action :check_auth_for_observe_user, except: [:check_user_id, :check_user_login]
|
||||||
|
|
||||||
def check_user_id
|
def check_user_id
|
||||||
return tip_exception(-1, "用户ID不存在") unless params[:user_id].present? && User.exists?(id: params[:user_id])
|
return tip_exception(-1, "用户ID不存在") unless params[:user_id].present? && User.exists?(id: params[:user_id])
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: openkylin_sign_details
|
||||||
|
#
|
||||||
|
# id :integer not null, primary key
|
||||||
|
# user_id :integer
|
||||||
|
# login :string(255)
|
||||||
|
# email :string(255)
|
||||||
|
# nickname :string(255)
|
||||||
|
# phone :string(255)
|
||||||
|
# address :string(255)
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
|
#
|
||||||
|
# Indexes
|
||||||
|
#
|
||||||
|
# index_openkylin_sign_details_on_user_id (user_id)
|
||||||
|
#
|
||||||
|
|
||||||
|
class OpenkylinSignDetail < ApplicationRecord
|
||||||
|
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,45 @@
|
||||||
|
class Api::V1::Users::OpenkylinSign::CreateService < ApplicationService
|
||||||
|
include ActiveModel::Model
|
||||||
|
|
||||||
|
attr_reader :observe_user, :login, :email, :nickname, :phone, :address
|
||||||
|
|
||||||
|
# validates :login, format: {with: CustomRegexp::LOGIN}
|
||||||
|
validates :email, format: {with: CustomRegexp::EMAIL}
|
||||||
|
validates :nickname, length: { maximum: 32 }
|
||||||
|
validates :phone, format: {with: CustomRegexp::PHONE}
|
||||||
|
validates :address, length: { maximum: 100 }
|
||||||
|
|
||||||
|
def initialize(observe_user, params={})
|
||||||
|
@observe_user = observe_user
|
||||||
|
@login = observe_user.login
|
||||||
|
@email = params[:email]
|
||||||
|
@nickname = params[:nickname]
|
||||||
|
@phone = params[:phone]
|
||||||
|
@address = params[:address]
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
raise Error, errors.full_messages.join(",") unless valid?
|
||||||
|
raise Error, '用户已经签署CLA协议!' if @observe_user.sign_cla
|
||||||
|
begin
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
create_openkylin_sign_detail
|
||||||
|
update_user_sign_cla
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
rescue
|
||||||
|
raise Error, "服务器错误,请联系系统管理员!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def create_openkylin_sign_detail
|
||||||
|
OpenkylinSignDetail.create!(user_id: @observe_user.id, login: @login, email: @email, nickname: @nickname, phone: @phone, address: @address)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_user_sign_cla
|
||||||
|
@observe_user.update_attributes!(sign_cla: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -24,6 +24,11 @@ defaults format: :json do
|
||||||
scope module: :users do
|
scope module: :users do
|
||||||
resources :projects, only: [:index]
|
resources :projects, only: [:index]
|
||||||
resources :feedbacks, only: [:create]
|
resources :feedbacks, only: [:create]
|
||||||
|
resources :openkylin_sign, only: [:create] do
|
||||||
|
collection do
|
||||||
|
get :competitions
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scope ':repo', constraints: { repo: /[^\/]+/ } do
|
scope ':repo', constraints: { repo: /[^\/]+/ } do
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
class CreateOpenkylinSignDetails < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :openkylin_sign_details do |t|
|
||||||
|
t.references :user
|
||||||
|
t.string :login
|
||||||
|
t.string :email
|
||||||
|
t.string :nickname
|
||||||
|
t.string :phone
|
||||||
|
t.string :address
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue