def clean_username(self): username = self.cleaned_data['username'] try: cass.get_user_by_username(username) raise forms.ValidationError(u'Username is already taken') except cass.DatabaseError: pass return username
def find_friends(request): friend_usernames = [] if request.user['is_authenticated']: friend_usernames = cass.get_friend_usernames( request.session['username']) + [request.session['username']] q = request.GET.get('q') result = None searched = False if q is not None: searched = True try: result = cass.get_user_by_username(q) result = { 'username': result.username, 'friend': q in friend_usernames } except cass.DatabaseError: pass context = { 'q': q, 'result': result, 'searched': searched, 'friend_usernames': friend_usernames, } return render_to_response( 'users/add_friends.html', context, context_instance=RequestContext(request))
def userline(request, username=None): try: user = cass.get_user_by_username(username) except cass.DatabaseError: raise Http404 # Query for the friend ids friend_usernames = [] if request.user['is_authenticated']: friend_usernames = cass.get_friend_usernames(username) + [username] # Add a property on the user to indicate whether the currently logged-in # user is friends with the user is_friend = username in friend_usernames start = request.GET.get('start') tweets, next_timeuuid = cass.get_userline(username, start=start, limit=NUM_PER_PAGE) context = { 'user': user, 'username': username, 'tweets': tweets, 'next': next_timeuuid, 'is_friend': is_friend, 'friend_usernames': friend_usernames, } return render_to_response( 'tweets/userline.html', context, context_instance=RequestContext(request))
def userline(request, username=None): try: user = cass.get_user_by_username(username) except cass.DatabaseError: raise Http404 # Query for the friend ids friend_usernames = [] if request.user['is_authenticated']: friend_usernames = cass.get_friend_usernames(username) + [username] # Add a property on the user to indicate whether the currently logged-in # user is friends with the user user['friend'] = username in friend_usernames start = request.GET.get('start') tweets, next = cass.get_userline(username, start=start, limit=NUM_PER_PAGE) context = { 'user': user, 'username': username, 'tweets': tweets, 'next': next, 'friend_usernames': friend_usernames, } return render_to_response('tweets/userline.html', context, context_instance=RequestContext(request))
def userline(request, username=None): try: user = cass.get_user_by_username(username) except cass.DatabaseError: raise Http404 # Query for the friend ids friend_ids = [] if request.user['is_authenticated']: friend_ids = cass.get_friend_ids(request.user['id']) + [request.user['id']] # Add a property on the user to indicate whether the currently logged-in # user is friends with the user user['friend'] = user['id'] in friend_ids start = request.GET.get('start') tweets = cass.get_userline(user['id'], start=start, limit=NUM_PER_PAGE + 1) next = None if tweets and len(tweets) == NUM_PER_PAGE + 1: next = tweets[-1]['_ts'] tweets = tweets[:NUM_PER_PAGE] context = { 'user': user, 'tweets': tweets, 'next': next, 'friend_ids': friend_ids, } return render_to_response('tweets/userline.html', context, context_instance=RequestContext(request))
def find_friends(request): friend_usernames = [] if request.user['is_authenticated']: friend_usernames = cass.get_friend_usernames( request.session['username']) + [request.session['username']] q = request.GET.get('q') result = None searched = False if q is not None: searched = True try: result = cass.get_user_by_username(q) result = { 'username': result.username, 'friend': q in friend_usernames } except cass.DatabaseError: pass context = { 'q': q, 'result': result, 'searched': searched, 'friend_usernames': friend_usernames, } return render_to_response('users/add_friends.html', context, context_instance=RequestContext(request))
def clean(self): username = self.cleaned_data['username'] password = self.cleaned_data['password'] try: user = cass.get_user_by_username(username) except cass.DatabaseError: raise forms.ValidationError(u'Invalid username and/or password') if user.password != password: raise forms.ValidationError(u'Invalid username and/or password') return self.cleaned_data
def clean(self): username = self.cleaned_data["username"] password = self.cleaned_data["password"] try: user = cass.get_user_by_username(username) except cass.DatabaseError: raise forms.ValidationError(u"Invalid username and/or password") if user.get("password") != password: raise forms.ValidationError(u"Invalid username and/or password") return self.cleaned_data
def get_user(request): if 'username' in request.session: try: user = cass.get_user_by_username(request.session['username']) user['is_authenticated'] = True return user except cass.DatabaseError: pass return { 'password': None, 'is_authenticated': False, }
def get_user(request): """ Function to read in the request data from the session, pull them from cassandra database, and log them in via django session """ if 'username' in request.session: try: user = cass.get_user_by_username(request.session['username']) return { 'username': user.username, 'password': user.password, 'is_authenticated': True } except cass.DatabaseError: pass return { 'password': None, 'is_authenticated': False, }
def get_user_id(self): username = self.cleaned_data['username'] user = cass.get_user_by_username(username) return user['id']