def done(self):
        # make sure the user doesn't already exist
        u = User.by_name(self.username)
        if u:
            msg = 'That user already exists.'
            self.render('signup-form.html',
                        error_username=msg,
                        username=self.username)
        else:
            u = User.register(self.username, self.password, self.email)
            u.put()

            self.login(u)
            self.redirect('/blog')
Beispiel #2
0
def get_user(update: Update, create=True):
    """
    get user from update
    :param update: update instance
    :param create: if set to true, will create user in db
    :return: User
    """

    user_data = update.message.from_user
    user = User.get_by_chat_id(user_data.id)
    if user:
        return user

    user = User.register(user_data.id, user_data.first_name,
                         user_data.last_name, user_data.username,
                         user_data.is_bot, save=create)
    return user