Beispiel #1
0
    def add_new_conversation(cls, sender, receiver, title, content):
        """Adds new conversation with receiver for sender, returns Conversation object

        Args:
         sender:    sender's username as string
         receiver:  receiver's username as string
         title:     title of the conversation
         content:   content of the first post

        Returns:
         tupple with:
          newly created Conversation instance
          newly created Message instance
        """
        #TODO: check if sender and receiver aren't the same person, if so, add only once

        skey = cls.get_user(sender).key
        rkey = cls.get_user(receiver).key

        if sender == receiver:
            rl = [skey]
            rln  = [sender]
        else:
            rl = [rkey, skey]
            rln = [sender, receiver]

        conv = Conversation(
            owner = skey,
            receivers_list = rl,
            receivers_list_norm = rln,
            title = title,
        )
        msg = Message(
            sender = sender,
            content = content
        )


        k = msg.put()
        conv.insert_message(k)
        ck = conv.put()

        User.add_conversation_for_users(ck, sender, receiver)

        return conv, msg
Beispiel #2
0
    def check_context(self, *args, **kwargs):
        user_id = self.request.get('user_id', None) or self._data().get(
            'user_id', None)

        if user_id:
            user = User.get_by_id(long(user_id))
            self.user = user
        else:
            self.user = None
        return handler(self, *args, **kwargs)
Beispiel #3
0
    def get_user(cls, username):
        """Get User instance for username

        Args:
         username:  string with username

        Returns:
         instance of User class for given username or None
        """
        return User.query(User.username == username).get()
Beispiel #4
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('pages.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in', 'success')
        return redirect(url_for('users.login'))
    return render_template('users/register.html', title='Register', form=form)
Beispiel #5
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('pages.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('Your password has been updated! You are now able to log in', 'success')
        return redirect(url_for('users.login'))
    return render_template('users/reset_token.html', title='Reset Password', form=form)
Beispiel #6
0
    def get_friends(self, limit=10, offset=0):
        """Gets friends for current User object

        Returns:
         A list of User objects who are current in current User's friends list or
         None if User's friends list is empty
        """
        if bool(self.friends):
            f = memcache.get('friends', namespace=self.username)
            if not f:
                f = User.query(User.username.IN(self.friends)).order(-User.username)\
                        .fetch(limit, offset=offset)
                memcache.set('friends', f, namespace=self.username, time=1440)
            return f
        return None
Beispiel #7
0
    def create_user(cls, provider_user_info):
        auth_id = "facebook:" + provider_user_info['id']
        unique_properties = ['email']

        user_result = User.create_user(
            auth_id,
            unique_properties,
            email=provider_user_info['email'],
            name=provider_user_info['name'],
            last_name=provider_user_info['last_name'],
            picture=provider_user_info['picture'],
            activated=True)

        if not user_result[0]:
            raise Exception("Email exists already. "
                            "Have you logged in already with Google perhaps?")

        return user_result[1]
Beispiel #8
0
    def get(self, **kwargs):
        user_session = self.user
        user_session_object = self.auth.store.get_session(self.request)

        user_info = User.get_by_id(long(self.user_id))
        user_info_object = self.auth.store.user_model.get_by_auth_token(
            user_session['user_id'], user_session['token'])

        try:
            params = {
                "user_session": user_session,
                "user_session_object": user_session_object,
                "user_info": user_info,
                "user_info_object": user_info_object,
                "userinfo_logout-url": self.auth_config['logout_url'],
            }
            return self.render_template('secure_zone.html', **params)
        except (AttributeError, KeyError), e:
            return "Secure zone error:" + " %s." % e
Beispiel #9
0
    def get(self, **kwargs):
        user_session = self.user
        user_session_object = self.auth.store.get_session(self.request)

        user_info = User.get_by_id(long( self.user_id ))
        user_info_object = self.auth.store.user_model.get_by_auth_token(
            user_session['user_id'], user_session['token'])

        try:
            params = {
                "user_session" : user_session,
                "user_session_object" : user_session_object,
                "user_info" : user_info,
                "user_info_object" : user_info_object,
                "userinfo_logout-url" : self.auth_config['logout_url'],
                }
            return self.render_template('secure_zone.html', **params)
        except (AttributeError, KeyError), e:
            return "Secure zone error:" + " %s." % e
Beispiel #10
0
    def create_user(cls, provider_user_info):
        auth_id = "google:%s" % provider_user_info['id']
        unique_properties = ['email']

        user_result = User.create_user(
            auth_id,
            unique_properties,
            email=provider_user_info['email'],
            name=provider_user_info['given_name'],
            last_name=provider_user_info['family_name'],
            picture=provider_user_info['picture'],
            activated=True
        )

        if not user_result[0]:
            raise Exception(
                "Email exists already. "
                "Have you logged in already with Facebook perhaps?"
            )

        return user_result[1]
 def get(self):
   if not decorator.has_credentials():
     return self.redirect(decorator.authorize_url())
   else:
     credentials = decorator.get_credentials()
   try:
     decorator.http()
   except:
     logging.error("Error: Decorator Refresh Failed")
   if credentials.refresh_token is None:
     logging.error("Error: Refresh Token is None")
   current_user = users.get_current_user()
   if current_user:
     uid = current_user.user_id()
     email = current_user.email()
   else:
     message = _('No user authentication information received from %s. '
               'Please ensure you are logging in from an authorized OpenID Provider (OP).'
               % provider_display_name)
     self.add_message(message, 'error')
     return self.redirect_to('login', continue_url=continue_url) if continue_url else self.redirect_to(
                   'login')
   if self.user:
       # add social account to user
       user_info = User.get_by_id(long(self.user_id))
       if SpreadSheetUser.check_unique_uid( uid):
         credential_user = SpreadSheetUser(
                 user=user_info.key,
                 uid=uid,
                 username= user_info.username,
                 credentials = credentials,
                 status = '1',
                 miners=['none']
             )
         credential_user.put() 
   return self.redirect('/settings/profile')
 def tearDownClass(cls):
     User.drop_collection()
     Role.drop_collection()
 def setUp(self):
     db.create_all()
     db.session.add(
         User(username="******", email="*****@*****.**", password="******")
     )
     db.session.commit()
 def get(self):
   user_info = User.get_by_id(long(self.user_id))
   credentials =SpreadSheetUser.get_by_username(user_info.username)
   if credentials.credentials.refresh_token is None:
     logging.error("Error: Refresh Token is None")
   return self.redirect('/settings/profile')