def add_users(request, code): usernames = request.POST.get('usernames', '') school = School.objects.filter(identity=code).first() count = 1 for name in clean(usernames).split(','): user_ob = User.objects.filter(username=name).first() if user_ob: if count == 1: school.created_by = user_ob school.users.add(user_ob) school.save() school.created_by = User.objects.filter(username=clean(usernames).split(',')).first() school.save() return redirect('signup:login')
def create_student(request): data = {'username': clean(request.POST.get('student-username', "")), 'first': str(request.POST.get('student-name', "")).split()[0], 'last': str(request.POST.get('student-name', "")).split()[1], 'email': clean(request.POST.get('student-email', "")), 'school': str(request.POST.get('student-school', "")), 'password': request.POST.get('student-password', ""), 'account': 1, 'gender': 0, 'pic_link': 'avatars/guy.png' } test = User.objects.filter(username=data['username']).first() if test: print(test) messages.add_message(request, messages.INFO, 'Username is taken.') return redirect('signup:index') if len(data['school']) > 10: find_school = School.objects.filter(identity=data['school']).first() if find_school is None: messages.add_message(request, messages.INFO, 'No school found with that ID') return redirect('signup:index') data['gender'] = int(request.POST.get('student-gender', data['gender'])) if data['gender'] is 1: data['pic_link'] = 'avatars/girl.png' user = User.objects.create_user(username=data['username'], first_name=data['first'], last_name=data['last'], email=data['email'], password=data['password']) user.save() find_school = School.objects.filter(identity=data['school']).first() if find_school: profile = Profile.objects.create(user=user, classification=data['account'], gender_type=data['gender']) user.schools.add(find_school) user.save() else: profile = Profile.objects.create(user=user, classification=data['account'], gender_type=data['gender']) profile.save() url = 'http://' + request.get_host() + '/signup/confirm/' + profile.email_confirm_code send_mail('Confirm Email for ' + user.username, 'Confirm your email with ' + user.username + 'by clicking this link: ' + url, '*****@*****.**', [user.email]) return redirect('signup:waiting')
def add_user(request, code): channel_ob = Channel.objects.filter(identity=code).first() user = User.objects.filter(username=clean(request.POST.get('name', ''))).first() if user: if channel_ob.users.filter(username=user.username).first() is None: channel_ob.users.add(user) channel_ob.save() event = Event.objects.create(text=request.user.profile.full_name + ' added ' + user.profile.full_name + ' to the group', project=channel_ob.projects.all()[0], type='usr') return redirect('channel:channel_view', code=code)
def create_teacher_school(request, code): data = {'username': clean(request.POST.get('teacher-username', "")), 'first': str(request.POST.get('teacher-name', "")).split()[0], 'last': str(request.POST.get('teacher-name', "")).split()[1], 'email': clean(request.POST.get('teacher-email', "")), 'school': str(request.POST.get('teacher-school', "")), 'password': request.POST.get('teacher-password', ""), 'account': 0, 'gender': 0, 'pic_link': 'avatars/guy.png', } test = User.objects.filter(username=data['username']).first() if test: print(test) messages.add_message(request, messages.INFO, 'Username is taken.') return redirect('signup:index') find_school = School.objects.filter(identity=code).first() if find_school is None: messages.add_message(request, messages.INFO, 'No school found with that ID') return redirect('signup:index') data['gender'] = int(request.POST.get('teacher-gender', data['gender'])) if data['gender'] is 1: data['pic_link'] = 'avatars/girl.png' user = User.objects.create_user(username=data['username'], first_name=data['first'], last_name=data['last'], email=data['email'], password=data['password']) user.save() profile = Profile.objects.create(user=user, classification=data['account'], gender_type=data['gender']) user.schools.add(find_school) find_school.created_by = user profile.email_confirmed = True find_school.save() user.save() profile.save() from django.contrib.auth import login user.backend = 'django.contrib.auth.backends.ModelBackend' login(request, profile.user) return redirect('dashboard:index')
def login_control(request): from django.contrib.auth import authenticate, login username = request.POST.get('username', '') password = request.POST.get('password', '') user = authenticate(username=clean(username), password=password) if user: login(request, user) return redirect('dashboard:index') else: return redirect('signup:login')
def create_project(request, code): channel_ob = Channel.objects.filter(identity=code).first() name = request.POST.get('name', '') project = Project.objects.create(name=name, channel=channel_ob, created_by=request.user) project.save() users = request.POST.get('users', '') event = Event.objects.create(text=request.user.profile.full_name + ' created the channel!', project=project, type='usr') event.save() if len(users) > 2: users = clean(users).split(',') for each in users: print(each) user = User.objects.filter(username=each).first() if user: event = Event.objects.create(text=user.profile.full_name + ' joined the group!', project=project, type='usr') print('FOUND!') channel_ob.users.add(user) channel_ob.save() return redirect('channel:channel_view', code=channel_ob.identity)
def create_direct(request): name = request.POST.get('username', '') user = User.objects.filter(username=clean(name)).first() return redirect('channel:direct_view')