|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | class Api::V1::AccountsController < Api::BaseController |
4 | | - before_action -> { authorize_if_got_token! :read, :'read:accounts' }, except: [:follow, :unfollow, :block, :unblock, :mute, :unmute] |
| 4 | + before_action -> { authorize_if_got_token! :read, :'read:accounts' }, except: [:create, :follow, :unfollow, :block, :unblock, :mute, :unmute] |
5 | 5 | before_action -> { doorkeeper_authorize! :follow, :'write:follows' }, only: [:follow, :unfollow] |
6 | 6 | before_action -> { doorkeeper_authorize! :follow, :'write:mutes' }, only: [:mute, :unmute] |
7 | 7 | before_action -> { doorkeeper_authorize! :follow, :'write:blocks' }, only: [:block, :unblock] |
| 8 | + before_action -> { doorkeeper_authorize! :write, :'write:accounts' }, only: [:create] |
8 | 9 |
|
9 | | - before_action :require_user!, except: [:show] |
10 | | - before_action :set_account |
| 10 | + before_action :require_user!, except: [:show, :create] |
| 11 | + before_action :set_account, except: [:create] |
11 | 12 | before_action :check_account_suspension, only: [:show] |
| 13 | + before_action :check_enabled_registrations, only: [:create] |
12 | 14 |
|
13 | 15 | respond_to :json |
14 | 16 |
|
15 | 17 | def show |
16 | 18 | render json: @account, serializer: REST::AccountSerializer |
17 | 19 | end |
18 | 20 |
|
| 21 | + def create |
| 22 | + token = AppSignUpService.new.call(doorkeeper_token.application, account_params) |
| 23 | + response = Doorkeeper::OAuth::TokenResponse.new(token) |
| 24 | + |
| 25 | + headers.merge!(response.headers) |
| 26 | + |
| 27 | + self.response_body = Oj.dump(response.body) |
| 28 | + self.status = response.status |
| 29 | + end |
| 30 | + |
19 | 31 | def follow |
20 | 32 | FollowService.new.call(current_user.account, @account, reblogs: truthy_param?(:reblogs)) |
21 | 33 |
|
@@ -62,4 +74,12 @@ def relationships(**options) |
62 | 74 | def check_account_suspension |
63 | 75 | gone if @account.suspended? |
64 | 76 | end |
| 77 | + |
| 78 | + def account_params |
| 79 | + params.permit(:username, :email, :password, :agreement) |
| 80 | + end |
| 81 | + |
| 82 | + def check_enabled_registrations |
| 83 | + forbidden if single_user_mode? || !Setting.open_registrations |
| 84 | + end |
65 | 85 | end |
0 commit comments