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:
commit
bbc85e1e29
|
@ -22,30 +22,25 @@ export default Ember.Component.extend({
|
|||
}
|
||||
},
|
||||
|
||||
@computed
|
||||
joinGroupAction() {
|
||||
return this.currentUser ? 'joinGroup' : 'showLogin';
|
||||
},
|
||||
|
||||
@computed
|
||||
requestMembershipAction() {
|
||||
return this.currentUser ? 'requestMembership' : 'showLogin';
|
||||
_showLoginModal() {
|
||||
this.sendAction('showLogin');
|
||||
$.cookie('destination_url', window.location.href);
|
||||
},
|
||||
|
||||
actions: {
|
||||
showLogin() {
|
||||
this.sendAction('showLogin');
|
||||
},
|
||||
|
||||
joinGroup() {
|
||||
this.set('updatingMembership', true);
|
||||
const model = this.get('model');
|
||||
if (this.currentUser) {
|
||||
this.set('updatingMembership', true);
|
||||
const model = this.get('model');
|
||||
|
||||
model.addMembers(this.currentUser.get('username')).then(() => {
|
||||
model.set('is_group_user', true);
|
||||
}).catch(popupAjaxError).finally(() => {
|
||||
this.set('updatingMembership', false);
|
||||
});
|
||||
model.addMembers(this.currentUser.get('username')).then(() => {
|
||||
model.set('is_group_user', true);
|
||||
}).catch(popupAjaxError).finally(() => {
|
||||
this.set('updatingMembership', false);
|
||||
});
|
||||
} else {
|
||||
this._showLoginModal();
|
||||
}
|
||||
},
|
||||
|
||||
leaveGroup() {
|
||||
|
@ -60,14 +55,18 @@ export default Ember.Component.extend({
|
|||
},
|
||||
|
||||
requestMembership() {
|
||||
const groupName = this.get('model.name');
|
||||
if (this.currentUser) {
|
||||
const groupName = this.get('model.name');
|
||||
|
||||
Group.loadOwners(groupName).then(result => {
|
||||
const names = result.map(owner => owner.username).join(",");
|
||||
const title = I18n.t('groups.request_membership_pm.title');
|
||||
const body = I18n.t('groups.request_membership_pm.body', { groupName });
|
||||
this.sendAction("createNewMessageViaParams", names, title, body);
|
||||
});
|
||||
Group.loadOwners(groupName).then(result => {
|
||||
const names = result.map(owner => owner.username).join(",");
|
||||
const title = I18n.t('groups.request_membership_pm.title');
|
||||
const body = I18n.t('groups.request_membership_pm.body', { groupName });
|
||||
this.sendAction("createNewMessageViaParams", names, title, body);
|
||||
});
|
||||
} else {
|
||||
this._showLoginModal();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
label="groups.leave"
|
||||
disabled=updatingMembership}}
|
||||
{{else}}
|
||||
{{d-button action=joinGroupAction
|
||||
{{d-button action="joinGroup"
|
||||
class="group-index-join"
|
||||
icon="plus"
|
||||
label="groups.join"
|
||||
|
@ -22,7 +22,7 @@
|
|||
disabled=true}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{d-button action=requestMembershipAction
|
||||
{{d-button action="requestMembership"
|
||||
class="group-index-request"
|
||||
icon="envelope"
|
||||
label="groups.request"}}
|
||||
|
|
|
@ -550,7 +550,13 @@ class UsersController < ApplicationController
|
|||
if Guardian.new(@user).can_access_forum?
|
||||
@user.enqueue_welcome_message('welcome_user') if @user.send_welcome_message
|
||||
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
|
||||
@needs_approval = true
|
||||
end
|
||||
|
|
|
@ -191,6 +191,27 @@ describe UsersController do
|
|||
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
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue