mirror of
https://framagit.org/tykayn/mastodon.git
synced 2023-08-25 08:33:12 +02:00
Redirect users back to app from confirmation if they were created with an app
This commit is contained in:
parent
05ef749a0f
commit
322869a685
@ -6,9 +6,9 @@ class Auth::ConfirmationsController < Devise::ConfirmationsController
|
||||
before_action :set_body_classes
|
||||
before_action :set_user, only: [:finish_signup]
|
||||
|
||||
# GET/PATCH /users/:id/finish_signup
|
||||
def finish_signup
|
||||
return unless request.patch? && params[:user]
|
||||
|
||||
if @user.update(user_params)
|
||||
@user.skip_reconfirmation!
|
||||
bypass_sign_in(@user)
|
||||
@ -31,4 +31,12 @@ class Auth::ConfirmationsController < Devise::ConfirmationsController
|
||||
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
|
||||
|
@ -36,6 +36,7 @@
|
||||
# invite_id :bigint(8)
|
||||
# remember_token :string
|
||||
# chosen_languages :string is an Array
|
||||
# created_by_application_id :bigint(8)
|
||||
#
|
||||
|
||||
class User < ApplicationRecord
|
||||
@ -66,6 +67,7 @@ class User < ApplicationRecord
|
||||
|
||||
belongs_to :account, inverse_of: :user
|
||||
belongs_to :invite, counter_cache: :uses, optional: true
|
||||
belongs_to :created_by_application, class_name: 'Doorkeeper::Application', optional: true
|
||||
accepts_nested_attributes_for :account
|
||||
|
||||
has_many :applications, class_name: 'Doorkeeper::Application', as: :owner
|
||||
|
@ -6,7 +6,7 @@ class AppSignUpService < BaseService
|
||||
|
||||
user_params = params.slice(:email, :password)
|
||||
account_params = params.slice(:username)
|
||||
user = User.create!(user_params.merge(password_confirmation: user_params[:password], account_attributes: account_params))
|
||||
user = User.create!(user_params.merge(created_by_application: app, password_confirmation: user_params[:password], account_attributes: account_params))
|
||||
|
||||
Doorkeeper::AccessToken.create!(application: app,
|
||||
resource_owner_id: user.id,
|
||||
|
@ -55,6 +55,10 @@
|
||||
%tbody
|
||||
%tr
|
||||
%td.button-primary
|
||||
- if @resource.created_by_application
|
||||
= link_to confirmation_url(@resource, confirmation_token: @token, redirect_to_app: 'true') do
|
||||
%span= t 'devise.mailer.confirmation_instructions.action_with_app', app: @resource.created_by_application.name
|
||||
- else
|
||||
= link_to confirmation_url(@resource, confirmation_token: @token) do
|
||||
%span= t 'devise.mailer.confirmation_instructions.action'
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
<%= t 'devise.mailer.confirmation_instructions.explanation', host: site_hostname %>
|
||||
|
||||
=> <%= confirmation_url(@resource, confirmation_token: @token) %>
|
||||
=> <%= confirmation_url(@resource, confirmation_token: @token, redirect_to_app: @resource.created_by_application ? 'true' : nil) %>
|
||||
|
||||
<%= strip_tags(t('devise.mailer.confirmation_instructions.extra_html', terms_path: about_more_url, policy_path: terms_url)) %>
|
||||
|
||||
|
@ -18,6 +18,7 @@ en:
|
||||
mailer:
|
||||
confirmation_instructions:
|
||||
action: Verify email address
|
||||
action_with_app: Confirm and return to %{app}
|
||||
explanation: You have created an account on %{host} with this email address. You are one click away from activating it. If this wasn't you, please ignore this email.
|
||||
extra_html: Please also check out <a href="%{terms_path}">the rules of the instance</a> and <a href="%{policy_path}">our terms of service</a>.
|
||||
subject: 'Mastodon: Confirmation instructions for %{instance}'
|
||||
|
@ -0,0 +1,8 @@
|
||||
class AddCreatedByApplicationIdToUsers < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_reference :users, :created_by_application, foreign_key: { to_table: 'oauth_applications', on_delete: :nullify }, index: false
|
||||
add_index :users, :created_by_application_id, algorithm: :concurrently
|
||||
end
|
||||
end
|
31
db/schema.rb
31
db/schema.rb
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2018_12_07_011115) do
|
||||
ActiveRecord::Schema.define(version: 2018_12_19_235220) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -76,6 +76,23 @@ ActiveRecord::Schema.define(version: 2018_12_07_011115) do
|
||||
t.index ["tag_id"], name: "index_account_tag_stats_on_tag_id", unique: true
|
||||
end
|
||||
|
||||
create_table "account_warning_presets", force: :cascade do |t|
|
||||
t.text "text", default: "", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "account_warnings", force: :cascade do |t|
|
||||
t.bigint "account_id"
|
||||
t.bigint "target_account_id"
|
||||
t.integer "action", default: 0, null: false
|
||||
t.text "text", default: "", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_account_warnings_on_account_id"
|
||||
t.index ["target_account_id"], name: "index_account_warnings_on_target_account_id"
|
||||
end
|
||||
|
||||
create_table "accounts", force: :cascade do |t|
|
||||
t.string "username", default: "", null: false
|
||||
t.string "domain"
|
||||
@ -333,6 +350,15 @@ ActiveRecord::Schema.define(version: 2018_12_07_011115) do
|
||||
t.index ["status_id"], name: "index_mentions_on_status_id"
|
||||
end
|
||||
|
||||
create_table "moves", force: :cascade do |t|
|
||||
t.bigint "account_id"
|
||||
t.bigint "target_account_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_moves_on_account_id"
|
||||
t.index ["target_account_id"], name: "index_moves_on_target_account_id"
|
||||
end
|
||||
|
||||
create_table "mutes", force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
@ -620,8 +646,10 @@ ActiveRecord::Schema.define(version: 2018_12_07_011115) do
|
||||
t.bigint "invite_id"
|
||||
t.string "remember_token"
|
||||
t.string "chosen_languages", array: true
|
||||
t.bigint "created_by_application_id"
|
||||
t.index ["account_id"], name: "index_users_on_account_id"
|
||||
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
|
||||
t.index ["created_by_application_id"], name: "index_users_on_created_by_application_id"
|
||||
t.index ["email"], name: "index_users_on_email", unique: true
|
||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||
end
|
||||
@ -711,6 +739,7 @@ ActiveRecord::Schema.define(version: 2018_12_07_011115) do
|
||||
add_foreign_key "subscriptions", "accounts", name: "fk_9847d1cbb5", on_delete: :cascade
|
||||
add_foreign_key "users", "accounts", name: "fk_50500f500d", on_delete: :cascade
|
||||
add_foreign_key "users", "invites", on_delete: :nullify
|
||||
add_foreign_key "users", "oauth_applications", column: "created_by_application_id", on_delete: :nullify
|
||||
add_foreign_key "web_push_subscriptions", "oauth_access_tokens", column: "access_token_id", on_delete: :cascade
|
||||
add_foreign_key "web_push_subscriptions", "users", on_delete: :cascade
|
||||
add_foreign_key "web_settings", "users", name: "fk_11910667b2", on_delete: :cascade
|
||||
|
Loading…
Reference in New Issue
Block a user