Exemple #1
0
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)
Exemple #2
0
def signupsns(request):
	user1=User.objects.get(username=str(request.user))
	thisstudent = Student.objects(user=user1.id)
	if len(thisstudent) > 0:
		request.session['is_mentor'] = False
	else: 
		studentnew = Student()
		studentnew.user = user1
		studentnew.save()
		request.session['is_mentor'] = False
	return HttpResponseRedirect('/search-mentor')
Exemple #3
0
def index(request):
	firstname = "";
	lastname = "";
	username = "";
	password = "";
	email = "";
	if request.method == 'GET':
		return render(request, 'myapp/signup.html', {'rangerDay':range(1,32),'rangerYear':range(2014,1905,-1),})
	elif request.method == 'POST':
		firstname = request.POST['txtFirstName']
		lastname = request.POST['txtLastName']
		username = request.POST['txtUserName']
		password = request.POST['txtPassWord']
		email= request.POST['txtEmail']
		try:
			user = User()
			user.username = username
			user.first_name = firstname
			user.last_name = lastname
			user.email = email
			user.set_password(password);
			user.save()
			
			_profile = UserProfile()
			_profile.user_id = user
			_profile.save()
			
			st = Student()
			st.user = user
			st.save()
			
			user.backend = 'mongoengine.django.auth.MongoEngineBackend'
			logout(request)
			login(request, user)
			request.session['is_mentor'] = False
			return HttpResponseRedirect('/search-mentor')
		except mongoengine.errors.NotUniqueError as e:
				return getSignupError(request,'ユーザーはすでに存在しています!',firstname,lastname,username,password,email)