-
Notifications
You must be signed in to change notification settings - Fork 4
Qiita login #8
Qiita login #8
Changes from all commits
df7153d
bdbcc38
6951186
7f47227
7ba531e
f96d0e9
1cd0497
252719d
af8d68b
ad2400b
1c88c77
28462ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Link } from 'react-router'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export default class AlertBar extends React.Component { | ||
|
||
render () { | ||
const { isEmailConfirmed } = this.props; | ||
|
||
return ( | ||
<div className='alert-bar'> | ||
{ | ||
(!isEmailConfirmed && | ||
<div className='alert'> | ||
<i className='fa fa-fw fa-exclamation-triangle' /><FormattedMessage id='alert_bar.email_confirm_alert' defaultMessage='Your email address is not confirmed. Please confirm the sent email.' /> | ||
</div> | ||
) | ||
} | ||
</div> | ||
); | ||
} | ||
|
||
} | ||
|
||
AlertBar.propTypes = { | ||
isEmailConfirmed: PropTypes.bool.isRequired, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { connect } from 'react-redux'; | ||
import AlertBar from '../components/alert_bar'; | ||
|
||
const mapStateToProps = state => ({ | ||
isEmailConfirmed: state.getIn(['meta', 'is_email_confirmed']), | ||
}); | ||
|
||
export default connect(mapStateToProps)(AlertBar); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.alert-bar { | ||
.alert { | ||
border: 1px solid transparent; | ||
border-radius: 4px; | ||
padding: 12px; | ||
|
||
color: DarkGoldenrod; | ||
background-color: Beige; | ||
border-color: Goldenrod; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,6 @@ | |
@import 'rtl'; | ||
|
||
@import 'themes'; | ||
@import 'alert'; | ||
@import 'code'; | ||
@import 'qiita'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
.qiita { | ||
.button { | ||
display: inline-block; | ||
margin-bottom: 0; | ||
font-weight: normal; | ||
text-align: center; | ||
vertical-align: middle; | ||
touch-action: manipulation; | ||
cursor: pointer; | ||
background-image: none; | ||
border: 1px solid transparent; | ||
white-space: nowrap; | ||
padding: 6px 12px; | ||
font-size: 14px; | ||
line-height: 1.42857; | ||
border-radius: 3px; | ||
-webkit-user-select: none; | ||
-moz-user-select: none; | ||
-ms-user-select: none; | ||
user-select: none; | ||
} | ||
|
||
.button-primary { | ||
border-color: #4ea30a; | ||
background-color: #59bb0c; | ||
color: #fff; | ||
} | ||
|
||
.registration { | ||
width: 100%; | ||
text-transform: none; | ||
} | ||
} | ||
|
||
.registrations { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
.qiita { | ||
width: 300px; | ||
margin: 5px auto; | ||
text-align: center; | ||
} | ||
|
||
.password_registration_closed_caution { | ||
width: 300px; | ||
margin: 10px auto; | ||
} | ||
|
||
.info a { | ||
color: white; | ||
text-transform: none; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
class Auth::OmniauthCallbacksController < Devise::OmniauthCallbacksController | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 今更なのですが、 ここで行っているのは結局 QiitaAuthorization モデルの作成ですし、Setting の方も QiitaAuthorizationsController なので There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. QiitaAuthorizationsを確かに作成してはいるのですが、どちらかと言うとここはDeviseの提供する仕組みの上でOmniauthのcallbackを処理する性格のほうが強いので、Deviseの命名に寄せていた方が良いと考えているのですが、どう思いますか? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Omniauthのcallbackを処理するが、実際には Oauth Server 側 (今回だとQiita) で明示的にResource Owner のリソースを OauthClient 受け渡すための callback url を記述しているので、omniauth という gem が提供している仕組みではあるが QiitaAuthorization を作成する、という考え方がしっくりくるのかな、と思った。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 補足すると、 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
これはたしかにそうだと思いますが、今回は素直に提供する仕組みに乗っかって様子見ようと思います。forkなので。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. なるほど、本家がそういう実装なのか。 okです 👌 |
||
def qiita | ||
auth_hash = request.env['omniauth.auth'] | ||
|
||
if current_user | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この 「current_user が存在した場合」というのは 既存の password 認証のアカウントに Qiita アカウントに紐付ける というプロセスなので、今すぐには必要ない部分ですか?(消す必要はないと思っているが確認です) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. はい、現状使われることはない部分です 🙆 |
||
authorization = QiitaAuthorization.find_or_initialize_by(uid: auth_hash[:uid]) do |qiita_authorization| | ||
authorization.user = current_user | ||
end | ||
|
||
if authorization.save | ||
flash[:notice] = I18n.t('omniauth_callbacks.success') | ||
else | ||
flash[:alert] = I18n.t('omniauth_callbacks.failure') | ||
end | ||
redirect_to settings_qiita_authorizations_path | ||
else | ||
if authorization = QiitaAuthorization.find_by(uid: auth_hash[:uid]) | ||
sign_in(authorization.user) | ||
redirect_to web_path | ||
else | ||
store_omniauth_auth | ||
redirect_to new_user_oauth_registration_path | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def store_omniauth_auth | ||
session[:devise_omniauth_auth] = request.env['omniauth.auth'] | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class OauthRegistrationsController < DeviseController | ||
layout 'auth' | ||
|
||
before_action :check_enabled_registrations | ||
before_action :require_omniauth_auth | ||
before_action :require_no_authentication | ||
|
||
def new | ||
@oauth_registration = Form::OauthRegistration.from_omniauth_auth(omniauth_auth) | ||
end | ||
|
||
def create | ||
@oauth_registration = Form::OauthRegistration.from_omniauth_auth(omniauth_auth) | ||
@oauth_registration.assign_attributes( | ||
params.require(:form_oauth_registration).permit(:email, :username, :password, :password_confirmation).merge(locale: I18n.locale) | ||
) | ||
|
||
if @oauth_registration.save | ||
sign_in(@oauth_registration.user) | ||
redirect_to web_path | ||
flash[:notice] = I18n.t('oauth_registration.success') | ||
else | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def omniauth_auth | ||
@omniauth_auth ||= session[:devise_omniauth_auth].try(:deep_symbolize_keys) | ||
end | ||
|
||
def check_enabled_registrations | ||
redirect_to root_path if single_user_mode? || !Setting.open_registrations | ||
end | ||
|
||
def require_omniauth_auth | ||
redirect_to root_path unless omniauth_auth | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class Settings::QiitaAuthorizationsController < ApplicationController | ||
layout 'admin' | ||
|
||
before_action :authenticate_user! | ||
|
||
def show | ||
@account = current_account | ||
@qiita_authorization = current_account.user.qiita_authorization | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultMessage
が使われるのはどのようなケースですか?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mastodonはja, en以外のlocaleを用意していて、それらの他のlocaleを使用している場合に使われます。