def save_profile_picture(strategy, user, response, details,is_new=False,*args,**kwargs): if strategy.backend.name == 'facebook': imgpro = 'http://graph.facebook.com/{0}/picture'.format(response['id']) elif strategy.backend.name == 'twitter': imgpro = response.get('profile_image_url', '').replace('_normal', '') elif strategy.backend.name == 'google-oauth2' and "picture" in response: imgpro = response['picture'] else: imgpro = "" try: if imgpro: try: thisprofile = UserProfile.objects(user_id=user) #ThaiNN Please review this code if len(thisprofile) == 0: upro = UserProfile() upro.user_id = user upro.images = imgpro upro.save() else: mypro = thisprofile[0] mypro.images = imgpro mypro.save() except Exception as e: print(e) except HTTPError: pass
def signinsns(request): is_mentor = False is_join = False defaultUserImage = "/images/avatar/default.png" if 'next' in request.GET: nextpage = request.GET['next'] else: nextpage = "" user1=User.objects.get(username=str(request.user)) thismentor = Mentor.objects(user=user1.id) thisstudent = Student.objects(user=user1.id) thiscurrijoined = Curriculumn.objects() username=str(request.user) avatar = "" user_images = "" try: thisprofile = UserProfile.objects(user_id=user1) request.session['user_images'] = thisprofile[0].images user_images= request.session['user_images'] except Exception as e: upro = UserProfile() upro.user_id = user1 upro.images = defaultUserImage upro.save() request.session['user_images'] = defaultUserImage print(e) for cl in thiscurrijoined: if username in cl.joined_user: is_join = True if len(thisstudent) == 0: studentnew = Student() studentnew.user = user1 studentnew.save() if len(thismentor) > 0: is_mentor = True request.session['is_mentor'] = is_mentor context = { 'avatar':avatar, 'user_images':user_images } if nextpage: return HttpResponseRedirect(nextpage,context) else: if is_mentor: return HttpResponseRedirect('/mentorview',context ) else: if is_join: return HttpResponseRedirect('/student-home',context) else: return HttpResponseRedirect('/search-mentor',context)
def index(request): username = "" password = "" defaultUserImage = "/images/avatar/default.png" if 'next' in request.GET: nextpage = request.GET['next'] else: nextpage = "" if request.method == 'GET': return render(request, 'myapp/signin.html', {}) elif request.method == 'POST': username = request.POST['txtUserName'] password = request.POST['txtPassWord'] try: user = User.objects.get(username=username) if user.check_password(password): logout(request) user.backend = 'mongoengine.django.auth.MongoEngineBackend' login(request, user) user_images = "" try: profile = UserProfile.objects(user_id=user) user_images = profile[0].images request.session['user_images'] = "/upload/" +user.username+"-avatar.jpg" except Exception as e: upro = UserProfile() upro.user_id = user upro.images = defaultUserImage upro.save() request.session['user_images'] = defaultUserImage print(e) context = { 'user_images':user_images, } if nextpage: return HttpResponseRedirect(nextpage,context) else: return HttpResponseRedirect('/custom-debit-detail?type=loan') else: c = { 'error_message':"User name or password does not correct", 'username':username, 'password':password, } c.update(csrf(request)) c.update(context_processors.user(request)) return render_to_response("myapp/signin.html", c) except Exception as e: c = { 'error_message':e, } c.update(csrf(request)) c.update(context_processors.user(request)) return render_to_response("myapp/signin.html", c) return render(request, 'myapp/signin.html', {})
def index(request): username = "" password = "" is_mentor=False is_join = False defaultUserImage = "/images/avatar/default.png" username=str(request.user) thiscurrijoined1 = Curriculumn.objects() for cl in thiscurrijoined1: if username in cl.joined_user: is_join = True if request.method == 'GET': return render(request, 'myapp/signin.html', {}) elif request.method == 'POST': username = request.POST['txtUserName'] password = request.POST['txtPassWord'] if 'next' in request.GET: nextpage = request.GET['next'] else: nextpage = "" try: user = User.objects.get(username=username) transaction = UserLogin() transaction.user = user transaction.save() if user.check_password(password): logout(request) user.backend = 'mongoengine.django.auth.MongoEngineBackend' login(request, user) mentor = Mentor.objects(user=user) if len(mentor) > 0: is_mentor = True request.session['is_mentor'] = is_mentor user_images = "" try: profile = UserProfile.objects(user_id=user) user_images = profile[0].images request.session['user_images'] = "/upload/" +user.username+"-avatar.jpg" except Exception as e: upro = UserProfile() upro.user_id = user upro.images = defaultUserImage upro.save() request.session['user_images'] = defaultUserImage print(e) context = { 'user_images':user_images, } if nextpage: return HttpResponseRedirect(nextpage,context) else: if is_mentor: return HttpResponseRedirect('/mentorview',context) else: if is_join: return HttpResponseRedirect('/student-home',context) else: return HttpResponseRedirect('/search-mentor',context) #return HttpResponseRedirect('/search-mentor') else: c = { 'error_message':"User name or password does not correct", 'username':username, 'password':password, } c.update(csrf(request)) c.update(context_processors.user(request)) return render_to_response("myapp/signin.html", c) except Exception as e: c = { 'error_message':e, } c.update(csrf(request)) c.update(context_processors.user(request)) return render_to_response("myapp/signin.html", c) return render(request, 'myapp/signin.html', {})