コード例 #1
0
ファイル: client.py プロジェクト: btbytes/lastuser
    def validate(self):
        rv = super(PermissionForm, self).validate()
        if not rv:
            return False

        if not valid_username(self.name.data):
            raise wtf.ValidationError("Name contains invalid characters")

        edit_obj = getattr(self, 'edit_obj', None)
        if edit_obj:
            edit_id = edit_obj.id
        else:
            edit_id = None

        existing = Permission.query.filter_by(name=self.name.data, allusers=True).first()
        if existing and existing.id != edit_id:
            self.name.errors.append("A global permission with that name already exists")
            return False

        if self.context.data == g.user.userid:
            existing = Permission.query.filter_by(name=self.name.data, user=g.user).first()
        else:
            org = Organization.query.filter_by(userid=self.context.data).first()
            if org:
                existing = Permission.query.filter_by(name=self.name.data, org=org).first()
            else:
                existing = None
        if existing and existing.id != edit_id:
            self.name.errors.append("You have another permission with the same name")
            return False

        return True
コード例 #2
0
ファイル: client.py プロジェクト: btbytes/lastuser
    def validate_name(self, field):
        if not valid_username(field.data):
            raise wtf.ValidationError("Name contains invalid characters.")

        existing = ResourceAction.query.filter_by(name=field.data, resource=self.edit_resource).first()
        if existing and existing.id != self.edit_id:
            raise wtf.ValidationError("An action with that name already exists for this resource")
コード例 #3
0
ファイル: login.py プロジェクト: lifeeth/lastuser
 def validate_username(self, field):
     if field.data in RESERVED_USERNAMES:
         raise wtf.ValidationError, "That name is reserved"
     if not valid_username(field.data):
         raise wtf.ValidationError, u"Invalid characters in name. Names must be made of ‘a-z’, ‘0-9’ and ‘-’, without trailing dashes"
     existing = User.query.filter_by(username=field.data).first()
     if existing is not None:
         raise wtf.ValidationError, "That username is taken"
コード例 #4
0
ファイル: profile.py プロジェクト: lifeeth/lastuser
 def validate_username(self, field):
     if not valid_username(field.data):
         raise wtf.ValidationError, "Invalid characters in username"
     if field.data == g.user.username:
         return
     existing = User.query.filter_by(username=field.data).first()
     if existing is not None:
         raise wtf.ValidationError, "That username is taken"
コード例 #5
0
ファイル: client.py プロジェクト: lifeeth/lastuser
    def validate_name(self, field):
        if not valid_username(field.data):
            raise wtf.ValidationError("Name contains invalid characters.")

        edit_id = getattr(self, 'edit_id', None)

        existing = Resource.query.filter_by(name=field.data).first()
        if existing and existing.id != edit_id:
            raise wtf.ValidationError("A resource with that name already exists")
コード例 #6
0
ファイル: profile.py プロジェクト: btbytes/lastuser
 def validate_username(self, field):
     if not valid_username(field.data):
         raise wtf.ValidationError, "Invalid characters in username"
     if field.data in RESERVED_USERNAMES:
         raise wtf.ValidationError, "That name is reserved"
     existing = User.query.filter_by(username=field.data).first()
     if existing is not None and existing.id != self.edit_obj.id:
         raise wtf.ValidationError, "That username is taken"
     existing = Organization.query.filter_by(name=field.data).first()
     if existing is not None:
         raise wtf.ValidationError, "That username is taken"
コード例 #7
0
ファイル: client.py プロジェクト: lifeeth/lastuser
    def validate_name(self, field):
        if not valid_username(field.data):
            raise wtf.ValidationError("Name contains invalid characters.")

        edit_id = getattr(self, 'edit_id', None)

        existing = Permission.query.filter_by(name=field.data, allusers=True).first()
        if existing and existing.id != edit_id:
            raise wtf.ValidationError("A global permission with that name already exists")

        existing = Permission.query.filter_by(name=field.data, user=g.user).first()
        if existing and existing.id != edit_id:
            raise wtf.ValidationError("You have another permission with the same name")
コード例 #8
0
ファイル: oauthclient.py プロジェクト: ankitdaf/lastuser
def config_external_id(service, service_name, user, userid, username, fullname, avatar, access_token, secret, token_type, next_url):
    session['avatar_url'] = avatar
    extid = UserExternalId.query.filter_by(service=service, userid=userid).first()
    session['userid_external'] = {'service': service, 'userid': userid, 'username': username}

    if extid is not None:
        extid.oauth_token = access_token
        extid.oauth_token_secret = secret
        extid.oauth_token_type = token_type
        extid.username = username  # For twitter: update username if it changed
        db.session.commit()
        login_internal(extid.user)
        flash('You have logged in as %s via %s' % (username, service_name))
        return
    else:
        # If caller wants this id connected to an existing user, do it.
        if not user:
            user = register_internal(None, fullname, None)
        extid = UserExternalId(user=user, service=service, userid=userid, username=username,
                               oauth_token=access_token, oauth_token_secret=secret,
                               oauth_token_type=token_type)
        # If the service provided a username that is valid for LastUser and not already in use, assign
        # it to this user
        if valid_username(username):
            if User.query.filter_by(username=username).first() is None:
                user.username = username
        db.session.add(extid)
        db.session.commit()
        login_internal(user)
        if user:
            flash('You have logged in as %s via %s. This id has been linked to your existing account' % (username, service_name))
        else:
            flash('You have logged in as %s via %s. This is your first time here' % (username, service_name))

        # redirect the user to profile edit page to fill in more details
        return url_for('profile_edit', _external=True, next=next_url)