Beispiel #1
0
    def from_data(cls, id, login, **kwargs):
        self = cls(None, None)
        self.id = id
        self.login = login

        if 'accounts' in kwargs:
            for type, address in kwargs['accounts']:
                if type in ACCOUNT_TYPES and not parse_email(address):
                    raise ValueError(address)
            self.accounts = kwargs['accounts']
        if 'profile' in kwargs:
            self.profile = kwargs['profile']
        if 'info' in kwargs:
            self.info = kwargs['info']
        if 'password' in kwargs and kwargs['password']:
            self.set_password(kwargs['password'])

        #self.info = {}

        return self
Beispiel #2
0
    def from_data(cls, id, login, **kwargs):
        self = cls(None, None)
        self.id = id
        self.login = login

        if 'accounts' in kwargs:
            for type, address in kwargs['accounts']:
                if type in ACCOUNT_TYPES and not parse_email(address):
                    raise ValueError(address)
            self.accounts = kwargs['accounts']
        if 'profile' in kwargs:
            self.profile = kwargs['profile']
        if 'info' in kwargs:
            self.info = kwargs['info']
        if 'password' in kwargs and kwargs['password']:
            self.set_password(kwargs['password'])

        #self.info = {}

        return self
Beispiel #3
0
    def add_account(self, type, address):
        if type in ACCOUNT_TYPES and not parse_email(address):
            raise ValueError(address)

        res = db.fetchone(
            "SELECT id FROM users.accounts "
            "WHERE type=%s AND address=%s;", [type, address])
        if res:
            return

        res = db.fetchone(
            "SELECT id FROM users.accounts_unconfirmed "
            "WHERE type=%s AND address=%s;", [type, address])
        if res:
            return

        code = '%s%s%s%s' % (settings.secret, datetime.now(), type, address)
        code = sha1(code).hexdigest().lower()
        self.accounts_add.append((type, address, code))

        cache_del("addr_id_login:%s" % address)

        return code
Beispiel #4
0
    def add_account(self, type, address):
        if type in ACCOUNT_TYPES and not parse_email(address):
            raise ValueError(address)

        res = db.fetchone("SELECT id FROM users.accounts "
                          "WHERE type=%s AND address=%s;",
                          [type, address])
        if res:
            return

        res = db.fetchone("SELECT id FROM users.accounts_unconfirmed "
                          "WHERE type=%s AND address=%s;",
                          [type, address])
        if res:
            return

        code = '%s%s%s%s' % (settings.secret, datetime.now(), type, address)
        code = sha1(code).hexdigest().lower()
        self.accounts_add.append((type, address, code))

        cache_del("addr_id_login:%s" % address)

        return code
Beispiel #5
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))
Beispiel #6
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))