Exemple #1
0
    def _authenticate(self, request):
            
        user = request.session.get('user')
        if user:
            p_obj = dbapi.get_profile(user)
            if  p_obj is not None:
                return twitter.Api(consumer_key=self.consumer_key, consumer_secret=self.consumer_secret, \
                                       access_token_key=p_obj.oauth_token, access_token_secret=p_obj.oauth_secret)

        token = oauth.Token(request.session['request_token']['oauth_token'],
                            request.session['request_token']['oauth_token_secret'])
        client = oauth.Client(self.consumer, token)
        resp, content = client.request(access_token_url, "POST")
        access_token_key = dict(urlparse.parse_qsl(content))

        screen_name = access_token_key['screen_name']
        request.session['screen_name'] = screen_name

        access_token = access_token_key['oauth_token']
        access_token_secret  = access_token_key['oauth_token_secret']

        user = dbapi.get_user(screen_name)
        if user is None:
            user = dbapi.create_user(screen_name,'*****@*****.**' % screen_name, access_token_secret)
            dbapi.create_profile(user, access_token, access_token_secret) 

        request.session['user'] = user
        return twitter.Api(consumer_key=self.consumer_key, consumer_secret=self.consumer_secret, \
                               access_token_key=access_token, access_token_secret=access_token_secret)
Exemple #2
0
 def create_user(self, name, passwd, role):
     """Delete user by id."""
     mytemplate = Template("""<%include file="user_ok.html"/>""", \
         lookup=self.myllokup)
     hashed_passwd = hash_password(passwd)
     data = create_user(self.connection, name, hashed_passwd[0], \
         hashed_passwd[1], role)
     if data:
         data = 'User created.'
     else:
         data = 'User not created.'
     return mytemplate.render(status=data)
Exemple #3
0
def signup(request):
	"""
	Creates new fresh userprofile
	"""
	username = request.POST.get('username')
	password = request.POST.get('password')
	email = request.POST.get('email')
	user = get_user(username=username)
	if user:
		return send_409({"error":"user already exist with this username"})
	user = create_user(username=username, password=password, email=email)
	location = request.POST.get('location')
	about_me = request.POST.get('about_me')
	create_user_profile(user=user,location=location,about_me=about_me)

	return send_200({"message":"profile successfuly created"})
Exemple #4
0
def add_user():
    if ('first_name' not in request.get_json()
            or 'last_name' not in request.get_json()
            or 'userid' not in request.get_json()
            or 'groups' not in request.get_json()):
        return 'first_name, last_name, userid, and groups are required', 400

    if db.get_user(request.get_json()['userid']):
        return 'User(%s) already exists' % request.get_json()['userid'], 418

    try:
        user = db.create_user(request.get_json()['first_name'],
                              request.get_json()['last_name'],
                              request.get_json()['userid'],
                              request.get_json()['groups'])
    except db.UserGroupDoesNotExist as e:
        return 'cannot create user, %s' % e, 400
    LOG.info('added %r', user)

    return user.to_json()