diff options
author | Rémy Coutable <remy@rymai.me> | 2017-02-10 21:34:58 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-02-10 21:34:58 +0300 |
commit | 6c62ec76c0bc7a15005c8add04dc1700d471b80b (patch) | |
tree | f52bc7b341dfa9231f7bbaa96b146582cfec67f5 /lib/api/users.rb | |
parent | 34c61c8c28001273667578cb7e624b270633f9c0 (diff) | |
parent | 6fab6d94cef853ed0d081dcea0fbfe390047b1c8 (diff) |
Merge branch '1051-api-create-users-without-password' into 'master'
Optionally make users created via the API set their password
Closes #1051
See merge request !8957
Diffstat (limited to 'lib/api/users.rb')
-rw-r--r-- | lib/api/users.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/api/users.rb b/lib/api/users.rb index 4980a90f952..82ac3886ac3 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -82,7 +82,9 @@ module API end params do requires :email, type: String, desc: 'The email of the user' - requires :password, type: String, desc: 'The password of the new user' + optional :password, type: String, desc: 'The password of the new user' + optional :reset_password, type: Boolean, desc: 'Flag indicating the user will be sent a password reset token' + at_least_one_of :password, :reset_password requires :name, type: String, desc: 'The name of the user' requires :username, type: String, desc: 'The username of the user' use :optional_attributes @@ -94,8 +96,18 @@ module API user_params = declared_params(include_missing: false) identity_attrs = user_params.slice(:provider, :extern_uid) confirm = user_params.delete(:confirm) + user = User.new(user_params.except(:extern_uid, :provider, :reset_password)) + + if user_params.delete(:reset_password) + user.attributes = { + force_random_password: true, + password_expires_at: nil, + created_by_id: current_user.id + } + user.generate_password + user.generate_reset_token + end - user = User.new(user_params.except(:extern_uid, :provider)) user.skip_confirmation! unless confirm if identity_attrs.any? |