Exemplo n.º 1
0
def create_public_workspace(registry=None):
    project_name = PUBLIC_PROJECT_NAME
    username = PUBLIC_PROJECT_USERNAME
    project_desc = "%s description" % project_name
    user_public_email = "%s@internal" % username
    # imports here for circular import references
    from apex.models import create_user, AuthUser
    from mobyle2.core.models.user import User
    import transaction

    ausr = AuthUser.get_by_login(username)
    modified = False
    if ausr is None:
        kwargs = {"email": user_public_email, "username": username, "login": username}
        if registry:
            kwargs["registry"] = registry
        ausr = create_user(**kwargs)
    else:
        ausr.username = username
        ausr.email = user_public_email
        ausr.login = username
        modified = True
    # running mobyle2 __init__ recreate default project if deleted
    # only after we are sure user is created
    usr = User.by_id(ausr.id)
    if modified:
        transaction.commit()
Exemplo n.º 2
0
 def save(self):
     infos = {'password': self.data.get('password', ''),
              'email': self.data.get('email', ''),
              'username': self.data.get('username', ''),
              'login': self.data.get('username', ''),
             }
     new_user = create_user(**infos)
     self.after_signup(new_user)
     return new_user
Exemplo n.º 3
0
 def save(self):
     infos = {
         'password': self.data.get('password', ''),
         'email': self.data.get('email', ''),
         'username': self.data.get('username', ''),
         'login': self.data.get('username', ''),
     }
     new_user = create_user(**infos)
     self.after_signup(new_user)
     return new_user
Exemplo n.º 4
0
def create_user(nick, password, superuser=True):
    """."""
    t = [amodels.AuthUser.get_by_login(nick) is None,
          amodels.AuthUser.get_by_username(nick) is None]
    if False in t: raise Exception('%s already exists'%nick)
    usr = amodels.create_user(**{
        'login':nick,
        'username':nick,
        'password':password,
        'email':'%s@mobyle2internal'%nick,
    })
    u = user.User.by_id(usr.id)
    roles, sroles = [], ["internal_user", "external_user"]
    if superuser:
        sroles.append("portal_administrator")
    for r in sroles:
        roles.append(auth.Role.by_name(auth.R[r]))
    for r in roles:
        u.global_roles.append(r)
    session.add(u)
    session.commit()
Exemplo n.º 5
0
def apex_callback(request):
    """ apex_callback(request):
    no return value, called with route_url('apex_callback', request)

    This is the URL that Velruse returns an OpenID request to
    """
    redir = request.GET.get('came_from',
                route_url(apex_settings('came_from_route'), request))
    headers = []
    login_failed = True
    reason = _('Login failed!')
    if 'token' in request.POST:
        token = request.POST['token']
        auth = apexid_from_token(token)
        if auth:
            login_failed = False
            user, email = None, ''
            if 'emails' in  auth['profile']:
                emails = auth['profile']['emails']
                if isinstance(emails[0], dict):
                    email = auth['profile']['emails'][0]['value']
                else:
                    email = auth['profile']['emails'][0]
            else:
                email = auth['profile'].get('verifiedEmail', '').strip()
            # first try by email
            if email:
                user = AuthUser.get_by_email(email)
            # then by id
            if user is None:
                user = search_user(auth['apexid'])
            if not user:
                user_infos = {'login': auth['apexid'], 'username': auth['name']}
                if email:
                    user_infos['email'] = email
                user = create_user(**user_infos)
                if apex_settings('create_openid_after'):
                    openid_after = get_module(apex_settings('create_openid_after'))
                    request = openid_after().after_signup(request, user)
            if apex_settings('openid_required'):
                openid_required = False
                for required in apex_settings('openid_required').split(','):
                    if not getattr(user, required):
                        openid_required = True
                if openid_required:
                    request.session['id'] = user.id
                    return HTTPFound(location='%s?came_from=%s' % \
                        (route_url('apex_openid_required', request), \
                        request.GET.get('came_from', \
                        route_url(apex_settings('came_from_route'), request))))
            using_ldap = 'ldap' in [a.get('domain', '') 
                                    for a in auth.get(
                                        "profile", {}).get("accounts", [])]
            external_user = True
            internal_user = using_ldap
            headers = apex_remember(request, user.id, 
                                    internal_user=internal_user, 
                                    external_user=external_user)
            redir = request.GET.get('came_from', \
                        route_url(apex_settings('came_from_route'), request))
            flash(_('Successfully Logged in, welcome!'), 'success')
        else:
            auth = get_velruse_token(token)
            reasont = ''
            if auth.get('code', None):
                reasont += 'Code %s : ' % auth['code']
            if auth.get('description', ''):
                reasont += _(auth['description'])
            if reasont:
                reason = reasont
            login_failed = True
    if login_failed:
        flash(reason)
    return HTTPFound(location=redir, headers=headers)
Exemplo n.º 6
0
def apex_callback(request):
    """ apex_callback(request):
    no return value, called with route_url('apex_callback', request)

    This is the URL that Velruse returns an OpenID request to
    """
    redir = request.GET.get(
        'came_from', route_url(apex_settings('came_from_route'), request))
    headers = []
    login_failed = True
    reason = _('Login failed!')
    if 'token' in request.POST:
        token = request.POST['token']
        auth = apexid_from_token(token)
        if auth:
            login_failed = False
            user, email = None, ''
            if 'emails' in auth['profile']:
                emails = auth['profile']['emails']
                if isinstance(emails[0], dict):
                    email = auth['profile']['emails'][0]['value']
                else:
                    email = auth['profile']['emails'][0]
            else:
                email = auth['profile'].get('verifiedEmail', '').strip()
            # first try by email
            if email:
                user = AuthUser.get_by_email(email)
            # then by id
            if user is None:
                user = search_user(auth['apexid'])
            if not user:
                user_infos = {
                    'login': auth['apexid'],
                    'username': auth['name']
                }
                if email:
                    user_infos['email'] = email
                user = create_user(**user_infos)
                if apex_settings('create_openid_after'):
                    openid_after = get_module(
                        apex_settings('create_openid_after'))
                    request = openid_after().after_signup(request, user)
            if apex_settings('openid_required'):
                openid_required = False
                for required in apex_settings('openid_required').split(','):
                    if not getattr(user, required):
                        openid_required = True
                if openid_required:
                    request.session['id'] = user.id
                    return HTTPFound(location='%s?came_from=%s' % \
                        (route_url('apex_openid_required', request), \
                        request.GET.get('came_from', \
                        route_url(apex_settings('came_from_route'), request))))
            using_ldap = 'ldap' in [
                a.get('domain', '')
                for a in auth.get("profile", {}).get("accounts", [])
            ]
            external_user = True
            internal_user = using_ldap
            headers = apex_remember(request,
                                    user.id,
                                    internal_user=internal_user,
                                    external_user=external_user)
            redir = request.GET.get('came_from', \
                        route_url(apex_settings('came_from_route'), request))
            flash(_('Successfully Logged in, welcome!'), 'success')
        else:
            auth = get_velruse_token(token)
            reasont = ''
            if auth.get('code', None):
                reasont += 'Code %s : ' % auth['code']
            if auth.get('description', ''):
                reasont += _(auth['description'])
            if reasont:
                reason = reasont
            login_failed = True
    if login_failed:
        flash(reason)
    return HTTPFound(location=redir, headers=headers)
Exemplo n.º 7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__docformat__ = 'restructuredtext en'

from apex.models import create_user
for i in range(1000):
    create_user(username='******'%i,
                password='******',
                email='*****@*****.**'%i,
                active='Y')

# vim:set et sts=4 ts=4 tw=80: