Example #1
0
def add_account(type, address):
    code = users.add_account(type, address)
    if not code:
        return xmpp_template('account_add_fail')
    return xmpp_template('account_add')
Example #2
0
def accounts():
    if env.request.method == 'GET':
        return render('/profile/accounts.html',
                      jids=env.user.get_accounts('xmpp'),
                      unconfirmed=env.user.get_unconfirmed_accounts('xmpp'),
                      active_jid=env.user.get_active_account('xmpp'),
                      saved=env.request.args('saved', False))

    errors = []

    if env.user.check_password_set():
        try:
            if not env.user.check_password(env.request.args('password')):
                errors.append('password')
        except KeyError:
            errors.append('password')

    jids_del = env.request.args('xmpp-del', [])
    if not isinstance(jids_del, list):
        jids_del = [jids_del]
    jids = filter(None, [jid.strip() for jid in jids_del])

    for jid in jids_del:
        env.user.del_account('xmpp', jid)

    jids = env.request.args('xmpp', [])
    if not isinstance(jids, list):
        jids = [jids]
    jids = filter(None, [jid.strip().decode('utf-8') for jid in jids])

    jids_err = []
    for jid in jids:
        try:
            if not parse_email(jid):
                raise ValueError
            users.add_account('xmpp', jid)
        except ValueError:
            jids_err.append(jid)
    if jids_err:
        errors.append('xmpp')

    jid_active = env.request.args('xmpp-set-active')
    if jid_active == 'new':
        jid_active = jids[0] if jids else None
    if jid_active in jids_del or jid_active in jids_err:
        jid_active = None

    if 'password' in errors:
        if not jid_active:
            jid_active = env.user.get_active_account('xmpp')
        return render('/profile/accounts.html',
                      jids=env.user.get_accounts('xmpp'),
                      active_jid=jid_active,
                      jids_err=jids, errors=errors)

    env.user.save()

    if jid_active:
        env.user.set_active_account('xmpp', jid_active)

    if errors:
        if not jid_active:
            jid_active = env.user.get_active_account('xmpp')
        return render('/profile/accounts.html',
                      jids=env.user.get_accounts('xmpp'),
                      active_jid=jid_active,
                      jids_err=jids_err, errors=errors)

    ulogin_del = env.request.args('ulogin-del')
    if ulogin_del:
        if not isinstance(ulogin_del, (list, tuple)):
            ulogin_del = [ulogin_del]

        for u in ulogin_del:
            network, uid = u.strip().split('|')
            env.user.unbind_ulogin(network, uid)

    return Response(redirect='%s://%s.%s/profile/accounts?saved=1' % \
                             (env.request.protocol,
                              env.user.login, settings.domain))
Example #3
0
def accounts():
    if env.request.method == 'GET':
        return render('/profile/accounts.html',
                      jids=env.user.get_accounts('xmpp'),
                      unconfirmed=env.user.get_unconfirmed_accounts('xmpp'),
                      active_jid=env.user.get_active_account('xmpp'),
                      saved=env.request.args('saved', False))

    errors = []

    if env.user.check_password_set():
        try:
            if not env.user.check_password(env.request.args('password')):
                errors.append('password')
        except KeyError:
            errors.append('password')

    jids_del = env.request.args('xmpp-del', [])
    if not isinstance(jids_del, list):
        jids_del = [jids_del]
    jids = filter(None, [jid.strip() for jid in jids_del])

    for jid in jids_del:
        env.user.del_account('xmpp', jid)

    jids = env.request.args('xmpp', [])
    if not isinstance(jids, list):
        jids = [jids]
    jids = filter(None, [jid.strip().decode('utf-8') for jid in jids])

    jids_err = []
    for jid in jids:
        try:
            if not parse_email(jid):
                raise ValueError
            users.add_account('xmpp', jid)
        except ValueError:
            jids_err.append(jid)
    if jids_err:
        errors.append('xmpp')

    jid_active = env.request.args('xmpp-set-active')
    if jid_active == 'new':
        jid_active = jids[0] if jids else None
    if jid_active in jids_del or jid_active in jids_err:
        jid_active = None

    if 'password' in errors:
        if not jid_active:
            jid_active = env.user.get_active_account('xmpp')
        return render('/profile/accounts.html',
                      jids=env.user.get_accounts('xmpp'),
                      active_jid=jid_active,
                      jids_err=jids,
                      errors=errors)

    env.user.save()

    if jid_active:
        env.user.set_active_account('xmpp', jid_active)

    if errors:
        if not jid_active:
            jid_active = env.user.get_active_account('xmpp')
        return render('/profile/accounts.html',
                      jids=env.user.get_accounts('xmpp'),
                      active_jid=jid_active,
                      jids_err=jids_err,
                      errors=errors)

    ulogin_del = env.request.args('ulogin-del')
    if ulogin_del:
        if not isinstance(ulogin_del, (list, tuple)):
            ulogin_del = [ulogin_del]

        for u in ulogin_del:
            network, uid = u.strip().split('|')
            env.user.unbind_ulogin(network, uid)

    return Response(redirect='%s://%s.%s/profile/accounts?saved=1' % \
                             (env.request.protocol,
                              env.user.login, settings.domain))
Example #4
0
def add_account(type, address):
    code = users.add_account(type, address)
    if not code:
        return xmpp_template('account_add_fail')
    return xmpp_template('account_add')