mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-11-02 04:54:25 +00:00
5d2fc6de32
* Add REST API for creating an account The method is available to apps with a token obtained via the client credentials grant. It creates a user and account records, as well as an access token for the app that initiated the request. The user is unconfirmed, and an e-mail is sent as usual. The method returns the access token, which the app should save for later. The REST API is not available to users with unconfirmed accounts, so the app must be smart to wait for the user to click a link in their e-mail inbox. The method is rate-limited by IP to 5 requests per 30 minutes. * Redirect users back to app from confirmation if they were created with an app * Add tests * Return 403 on the method if registrations are not open * Require agreement param to be true in the API when creating an account
43 lines
900 B
Ruby
43 lines
900 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Auth::ConfirmationsController < Devise::ConfirmationsController
|
|
layout 'auth'
|
|
|
|
before_action :set_body_classes
|
|
before_action :set_user, only: [:finish_signup]
|
|
|
|
def finish_signup
|
|
return unless request.patch? && params[:user]
|
|
|
|
if @user.update(user_params)
|
|
@user.skip_reconfirmation!
|
|
bypass_sign_in(@user)
|
|
redirect_to root_path, notice: I18n.t('devise.confirmations.send_instructions')
|
|
else
|
|
@show_errors = true
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def set_user
|
|
@user = current_user
|
|
end
|
|
|
|
def set_body_classes
|
|
@body_classes = 'lighter'
|
|
end
|
|
|
|
def user_params
|
|
params.require(:user).permit(:email)
|
|
end
|
|
|
|
def after_confirmation_path_for(_resource_name, user)
|
|
if user.created_by_application && truthy_param?(:redirect_to_app)
|
|
user.created_by_application.redirect_uri
|
|
else
|
|
super
|
|
end
|
|
end
|
|
end
|