diff --git a/app/controllers/auth/confirmations_controller.rb b/app/controllers/auth/confirmations_controller.rb
index 7af9cbe81..c28c7471c 100644
--- a/app/controllers/auth/confirmations_controller.rb
+++ b/app/controllers/auth/confirmations_controller.rb
@@ -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
diff --git a/app/models/user.rb b/app/models/user.rb
index 44e0d1113..588a7ff91 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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
diff --git a/app/services/app_sign_up_service.rb b/app/services/app_sign_up_service.rb
index 09372b8c2..16b9270a4 100644
--- a/app/services/app_sign_up_service.rb
+++ b/app/services/app_sign_up_service.rb
@@ -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,
diff --git a/app/views/user_mailer/confirmation_instructions.html.haml b/app/views/user_mailer/confirmation_instructions.html.haml
index 1f088a16f..f75f7529a 100644
--- a/app/views/user_mailer/confirmation_instructions.html.haml
+++ b/app/views/user_mailer/confirmation_instructions.html.haml
@@ -55,8 +55,12 @@
%tbody
%tr
%td.button-primary
- = link_to confirmation_url(@resource, confirmation_token: @token) do
- %span= t 'devise.mailer.confirmation_instructions.action'
+ - 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'
%table.email-table{ cellspacing: 0, cellpadding: 0 }
%tbody
diff --git a/app/views/user_mailer/confirmation_instructions.text.erb b/app/views/user_mailer/confirmation_instructions.text.erb
index e01eecb27..65b4626c6 100644
--- a/app/views/user_mailer/confirmation_instructions.text.erb
+++ b/app/views/user_mailer/confirmation_instructions.text.erb
@@ -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)) %>
diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml
index 20938e47b..bd0642b25 100644
--- a/config/locales/devise.en.yml
+++ b/config/locales/devise.en.yml
@@ -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 the rules of the instance and our terms of service.
subject: 'Mastodon: Confirmation instructions for %{instance}'
diff --git a/db/migrate/20181219235220_add_created_by_application_id_to_users.rb b/db/migrate/20181219235220_add_created_by_application_id_to_users.rb
new file mode 100644
index 000000000..17ce900af
--- /dev/null
+++ b/db/migrate/20181219235220_add_created_by_application_id_to_users.rb
@@ -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
diff --git a/db/schema.rb b/db/schema.rb
index 51ac43e1d..92060f3ef 100644
--- a/db/schema.rb
+++ b/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