summaryrefslogtreecommitdiff
path: root/lib/api/internal.rb
diff options
context:
space:
mode:
authorRégis Freyd (GitLab) <regis@gitlab.com>2016-09-06 14:06:16 +0000
committerRégis Freyd (GitLab) <regis@gitlab.com>2016-09-06 14:06:16 +0000
commitb44636c259e7a655a60cc2b98431d6d00a73e002 (patch)
tree93545ea821319c23410a444f676c8e5a66daeecf /lib/api/internal.rb
parent310beb9002f1bbdd07abe5bba6712769773a99b2 (diff)
parente9e8c67fb7d58288dbac1777b63ea7d3128d6268 (diff)
downloadgitlab-ce-email-in-slash-commands.tar.gz
Merge branch 'master' into 'email-in-slash-commands'email-in-slash-commands
# Conflicts: # doc/user/project/slash_commands.md # doc/workflow/README.md
Diffstat (limited to 'lib/api/internal.rb')
-rw-r--r--lib/api/internal.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/api/internal.rb b/lib/api/internal.rb
index d8e9ac406c4..6e6efece7c4 100644
--- a/lib/api/internal.rb
+++ b/lib/api/internal.rb
@@ -101,6 +101,35 @@ module API
{}
end
end
+
+ post '/two_factor_recovery_codes' do
+ status 200
+
+ key = Key.find_by(id: params[:key_id])
+
+ unless key
+ return { 'success' => false, 'message' => 'Could not find the given key' }
+ end
+
+ if key.is_a?(DeployKey)
+ return { success: false, message: 'Deploy keys cannot be used to retrieve recovery codes' }
+ end
+
+ user = key.user
+
+ unless user
+ return { success: false, message: 'Could not find a user for the given key' }
+ end
+
+ unless user.two_factor_enabled?
+ return { success: false, message: 'Two-factor authentication is not enabled for this user' }
+ end
+
+ codes = user.generate_otp_backup_codes!
+ user.save!
+
+ { success: true, recovery_codes: codes }
+ end
end
end
end