def activate_user(user_id): user = User.from_id(user_id) # the user will have a new current_session_id set by the API - store it in the cookie for future requests session['current_session_id'] = user.current_session_id organisation_id = session.get('organisation_id') activated_user = user.activate() activated_user.login() invited_user = InvitedUser.from_session() if invited_user: service_id = _add_invited_user_to_service(invited_user) service = Service.from_id(service_id) if service.has_permission('broadcast'): return redirect( url_for('main.broadcast_tour', service_id=service.id, step_index=1)) return redirect( url_for('main.service_dashboard', service_id=service_id)) invited_org_user = InvitedOrgUser.from_session() if invited_org_user: user_api_client.add_user_to_organisation(invited_org_user.organisation, session['user_details']['id']) if organisation_id: return redirect( url_for('main.organisation_dashboard', org_id=organisation_id)) else: return redirect(url_for('main.add_service', first='first'))
def register_from_org_invite(): invited_org_user = session.get('invited_org_user') if not invited_org_user: abort(404) form = RegisterUserFromOrgInviteForm(invited_org_user, ) form.auth_type.data = 'sms_auth' if form.validate_on_submit(): if (form.organisation.data != invited_org_user['organisation'] or form.email_address.data != invited_org_user['email_address']): abort(400) _do_registration(form, send_email=False, send_sms=True, organisation_id=invited_org_user['organisation']) org_invite_api_client.accept_invite(invited_org_user['organisation'], invited_org_user['id']) user_api_client.add_user_to_organisation( invited_org_user['organisation'], session['user_details']['id']) return redirect(url_for('main.verify')) return render_template('views/register-from-org-invite.html', invited_org_user=invited_org_user, form=form)
def accept_org_invite(token): invited_org_user = org_invite_api_client.check_token(token) if not current_user.is_anonymous and current_user.email_address.lower( ) != invited_org_user.email_address.lower(): message = Markup(""" You’re signed in as {}. This invite is for another email address. <a href={}>Sign out</a> and click the link again to accept this invite. """.format(current_user.email_address, url_for("main.sign_out", _external=True))) flash(message=message) abort(403) if invited_org_user.status == 'cancelled': invited_by = user_api_client.get_user(invited_org_user.invited_by) organisation = organisations_client.get_organisation( invited_org_user.organisation) return render_template('views/cancelled-invitation.html', from_user=invited_by.name, organisation_name=organisation['name']) if invited_org_user.status == 'accepted': session.pop('invited_org_user', None) return redirect( url_for('main.organisation_dashboard', org_id=invited_org_user.organisation)) session['invited_org_user'] = invited_org_user.serialize() existing_user = user_api_client.get_user_by_email_or_none( invited_org_user.email_address) organisation_users = user_api_client.get_users_for_organisation( invited_org_user.organisation) if existing_user: org_invite_api_client.accept_invite(invited_org_user.organisation, invited_org_user.id) if existing_user not in organisation_users: user_api_client.add_user_to_organisation( invited_org_user.organisation, existing_user.id) return redirect( url_for('main.organisation_dashboard', org_id=invited_org_user.organisation)) else: return redirect(url_for('main.register_from_org_invite'))
def activate_user(user_id): user = User.from_id(user_id) # the user will have a new current_session_id set by the API - store it in the cookie for future requests session['current_session_id'] = user.current_session_id organisation_id = session.get('organisation_id') activated_user = user.activate() activated_user.login() invited_user = session.get('invited_user') if invited_user: service_id = _add_invited_user_to_service(invited_user) return redirect( url_for('main.service_dashboard', service_id=service_id)) invited_org_user = session.get('invited_org_user') if invited_org_user: user_api_client.add_user_to_organisation( invited_org_user['organisation'], session['user_details']['id']) if organisation_id: return redirect( url_for('main.organisation_dashboard', org_id=organisation_id)) else: return redirect(url_for('main.add_service', first='first'))
def activate_user(user_id): user = User.from_id(user_id) # the user will have a new current_session_id set by the API - store it in the cookie for future requests session["current_session_id"] = user.current_session_id organisation_id = session.get("organisation_id") activated_user = user.activate() activated_user.login() invited_user = session.get("invited_user") if invited_user: service_id = _add_invited_user_to_service(invited_user) return redirect( url_for("main.service_dashboard", service_id=service_id)) invited_org_user = session.get("invited_org_user") if invited_org_user: user_api_client.add_user_to_organisation( invited_org_user["organisation"], session["user_details"]["id"]) if organisation_id: return redirect( url_for("main.organisation_dashboard", org_id=organisation_id)) else: return redirect(url_for("main.welcome"))