Merge pull request #4750 from discourse/group_login_registration_flow

FEATURE: Redirect to groups page and apply group actions upon login/s…
This commit is contained in:
Guo Xiang Tan 2017-03-16 09:50:56 +08:00 committed by GitHub
commit bbc85e1e29
4 changed files with 55 additions and 29 deletions

View File

@ -22,30 +22,25 @@ export default Ember.Component.extend({
} }
}, },
@computed _showLoginModal() {
joinGroupAction() { this.sendAction('showLogin');
return this.currentUser ? 'joinGroup' : 'showLogin'; $.cookie('destination_url', window.location.href);
},
@computed
requestMembershipAction() {
return this.currentUser ? 'requestMembership' : 'showLogin';
}, },
actions: { actions: {
showLogin() {
this.sendAction('showLogin');
},
joinGroup() { joinGroup() {
this.set('updatingMembership', true); if (this.currentUser) {
const model = this.get('model'); this.set('updatingMembership', true);
const model = this.get('model');
model.addMembers(this.currentUser.get('username')).then(() => { model.addMembers(this.currentUser.get('username')).then(() => {
model.set('is_group_user', true); model.set('is_group_user', true);
}).catch(popupAjaxError).finally(() => { }).catch(popupAjaxError).finally(() => {
this.set('updatingMembership', false); this.set('updatingMembership', false);
}); });
} else {
this._showLoginModal();
}
}, },
leaveGroup() { leaveGroup() {
@ -60,14 +55,18 @@ export default Ember.Component.extend({
}, },
requestMembership() { requestMembership() {
const groupName = this.get('model.name'); if (this.currentUser) {
const groupName = this.get('model.name');
Group.loadOwners(groupName).then(result => { Group.loadOwners(groupName).then(result => {
const names = result.map(owner => owner.username).join(","); const names = result.map(owner => owner.username).join(",");
const title = I18n.t('groups.request_membership_pm.title'); const title = I18n.t('groups.request_membership_pm.title');
const body = I18n.t('groups.request_membership_pm.body', { groupName }); const body = I18n.t('groups.request_membership_pm.body', { groupName });
this.sendAction("createNewMessageViaParams", names, title, body); this.sendAction("createNewMessageViaParams", names, title, body);
}); });
} else {
this._showLoginModal();
}
} }
} }
}); });

View File

@ -6,7 +6,7 @@
label="groups.leave" label="groups.leave"
disabled=updatingMembership}} disabled=updatingMembership}}
{{else}} {{else}}
{{d-button action=joinGroupAction {{d-button action="joinGroup"
class="group-index-join" class="group-index-join"
icon="plus" icon="plus"
label="groups.join" label="groups.join"
@ -22,7 +22,7 @@
disabled=true}} disabled=true}}
{{/if}} {{/if}}
{{else}} {{else}}
{{d-button action=requestMembershipAction {{d-button action="requestMembership"
class="group-index-request" class="group-index-request"
icon="envelope" icon="envelope"
label="groups.request"}} label="groups.request"}}

View File

@ -550,7 +550,13 @@ class UsersController < ApplicationController
if Guardian.new(@user).can_access_forum? if Guardian.new(@user).can_access_forum?
@user.enqueue_welcome_message('welcome_user') if @user.send_welcome_message @user.enqueue_welcome_message('welcome_user') if @user.send_welcome_message
log_on_user(@user) log_on_user(@user)
return redirect_to(wizard_path) if Wizard.user_requires_completion?(@user)
if Wizard.user_requires_completion?(@user)
return redirect_to(wizard_path)
elsif destination_url = cookies[:destination_url]
cookies[:destination_url] = nil
return redirect_to(destination_url)
end
else else
@needs_approval = true @needs_approval = true
end end

View File

@ -191,6 +191,27 @@ describe UsersController do
end end
end end
describe '#perform_account_activation' do
describe 'when cookies contains a destination URL' do
let(:token) { 'asdadwewq' }
let(:user) { Fabricate(:user) }
before do
UsersController.any_instance.stubs(:honeypot_or_challenge_fails?).returns(false)
EmailToken.expects(:confirm).with(token).returns(user)
end
it 'should redirect to the URL' do
destination_url = 'http://thisisasite.com/somepath'
request.cookies[:destination_url] = destination_url
put :perform_account_activation, token: token
expect(response).to redirect_to(destination_url)
end
end
end
describe '.password_reset' do describe '.password_reset' do
let(:user) { Fabricate(:user) } let(:user) { Fabricate(:user) }