-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add instructions to set password for OAuth users (#346)
- Loading branch information
Showing
13 changed files
with
116 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class PasswordsController < Devise::PasswordsController | ||
# Needed to have Current.tenant available in Devise's controllers | ||
prepend_before_action :load_tenant_data | ||
|
||
# Needed for OAuth users (otherwise an already logged in user wouldn't be able to reset their password) | ||
skip_before_action :require_no_authentication, :only => [:edit, :update] | ||
|
||
def update | ||
super | ||
|
||
if resource.errors.empty? | ||
resource.update!(has_set_password: true) unless resource.has_set_password? | ||
|
||
# See: https://stackoverflow.com/a/22110985/1857435 | ||
sign_out(resource_name) | ||
sign_in(resource_name, resource) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/javascript/components/UserProfile/SetPasswordDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as React from 'react'; | ||
import I18n from 'i18n-js'; | ||
|
||
import Button from '../common/Button'; | ||
import buildRequestHeaders from '../../helpers/buildRequestHeaders'; | ||
|
||
interface Props { | ||
sendSetPasswordInstructionsEndpoint: string; | ||
authenticityToken: string; | ||
} | ||
|
||
const SetPasswordDialog = ({ sendSetPasswordInstructionsEndpoint, authenticityToken }: Props) => { | ||
|
||
|
||
return ( | ||
<div style={{margin: 8, padding: 16, backgroundColor: '#cce5ff', borderRadius: 4}}> | ||
<p> | ||
{ I18n.t('common.forms.auth.no_password_set') } | ||
</p> | ||
|
||
<Button | ||
type='button' | ||
onClick={async (event) => { | ||
const res = await fetch(sendSetPasswordInstructionsEndpoint, { | ||
method: 'GET', | ||
headers: buildRequestHeaders(authenticityToken) | ||
}); | ||
|
||
if (res.ok) { | ||
alert(I18n.t('devise.passwords.send_instructions')); | ||
} else { | ||
alert(I18n.t('common.errors.unknown')); | ||
} | ||
}}> | ||
{ I18n.t('common.forms.auth.set_password') } | ||
</Button> | ||
</div> | ||
) | ||
}; | ||
|
||
export default SetPasswordDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddHasSetPasswordToUsers < ActiveRecord::Migration[6.1] | ||
def change | ||
add_column :users, :has_set_password, :boolean, default: true, null: false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters