def rename(login): old = env.user.login env.user.rename(login) set_sessions_param(env.user, 'login', login) subs = [ u.id for u in env.user.subscribers() ] publish('sub', {'to': subs, 'a': 'rename', 'old': old, 'new': login})
def rename(login): old = env.user.login env.user.rename(login) set_sessions_param(env.user, 'login', login) subs = [u.id for u in env.user.subscribers()] publish('sub', {'to': subs, 'a': 'rename', 'old': old, 'new': login})
def add_account(type, address): code = env.user.add_account(type, address) if not code: return False env.user.save() publish('confirm', {'type': type, 'address': address, 'user': env.user.login, 'code': code}) return code
def add_to_whitelist(login): if isinstance(login, User): user = login else: user = User('login', login) if env.user.id == user.id: raise SubscribeError res = env.user.add_to_whitelist(user) if res: publish('sub', {'to': user.id, 'a': 'wl', 'from': env.user.login}) return res
def request_password(user): if not user.id: raise UserNotFound address = user.get_active_account('xmpp') if not address: raise AddressNotFound code = sha256('%s%s' % (datetime.now(), randint(1000000, 9999999))).hexdigest() key = 'reset-password:%s' % code redis = RedisPool(settings.storage_socket) redis.set(key, user.id) redis.expire(key, 60 * 60 * 24) publish('remember', {'type': 'xmpp', 'address': address, 'code': code})
def add_to_whitelist(login): if isinstance(login, User): user = login else: user = User('login', login) if env.user.id == user.id: raise SubscribeError res = env.user.add_to_whitelist(user) if res: publish('sub', {'to':user.id, 'a':'wl', 'from':env.user.login}) return res
def subscribe(login): """Subscribe to user returns True if subscribed, and False if subscription request is sent """ if isinstance(login, User): user = login else: user = User('login', login) if env.user.id == user.id: raise SubscribeError if user.add_subscription_request(env.user): publish('sub', {'to': user.id, 'a': 'sub', 'from': env.user.login}) log.info('sub %d %s' % (user.id, env.user.login)) return True else: publish('sub', {'to': user.id, 'a': 'req', 'from': env.user.login}) log.info('sub request %d %s' % (user.id, env.user.login)) return False
def subscribe(login): """Subscribe to user returns True if subscribed, and False if subscription request is sent """ if isinstance(login, User): user = login else: user = User('login', login) if env.user.id == user.id: raise SubscribeError if user.add_subscription_request(env.user): publish('sub', {'to':user.id, 'a':'sub', 'from':env.user.login}) log.info('sub %d %s' % (user.id, env.user.login)) return True else: publish('sub', {'to':user.id, 'a':'req', 'from':env.user.login}) log.info('sub request %d %s' % (user.id, env.user.login)) return False