def join(): form = JoinForm() if request.method == 'POST': if form.validate_on_submit(): # get form data username = form.username.data learner_name = form.learner_name.data email = form.email.data hashed_password = generate_password_hash(form.password.data) # add form data to database info = { "username": username, "password": hashed_password, "email": email, "learner_name": learner_name, 'added': datetime.utcnow(), } db.users.insert_one(info) # add info to session session["email"] = email session["username"] = username session["learner_name"] = learner_name # log app.logger.info('%s joined successfully', username) # flash message flash('You have successfully registered and logged in') return redirect('/dashboard') else: # add what happens if it doesn't validate for item in form.errors.items(): app.logger.error("item") return render_template('join.html', form=form)
def join(request, code): """ TODO: After registring a user invitation should be disable. """ if not check_invitation(code): messages.error(request, 'Your personal URL is incorrect, please ask for new invitation or provide proper url') return redirect('index') from forms import JoinForm if request.method == 'POST': form = JoinForm(request.POST) if form.is_valid(): profile=Profile(first_name=form.cleaned_data['first_name'], last_name=form.cleaned_data['last_name'], unit=form.cleaned_data['unit'], email=form.cleaned_data['email'], key=generate_key()) profile.save() keywords = __to_keywords(form.cleaned_data['keywords']) profile.keywords.clear(); for k in keywords: profile.keywords.add(k) profile.save() return redirect('homepage', code=profile.key ) else: form = JoinForm(initial={'key':code}) return render_to_response('researchers/join.html', { 'form': form, 'key':code, # invitation code },context_instance=RequestContext(request)) return render_to_response('researchers/join.html', {'form':form}, context_instance=RequestContext(request))
def join_project(request, project_author, project_pk): user = request.user project = get_object_or_404(Project, pk=project_pk) if project.wont_be_completed: return oops("This project won't be completed: you can't join it.") if request.method == "POST": form = JoinForm(request.POST) role = form.cleaned_data["role"] if form.is_valid(): project.add_interested_user(user, role) project_notification( project, user, "Clusterify -- user wants to join project", render_to_string( "projects/emails/author_approve_join.txt", {"project": project, "role": role, "joining_user": user, "site_url": get_full_url()}, ), True, ) else: user.message_set.create( message="Something was wrong with your form. Please note that your role description may not be longer than 120 characters. " % role ) return HttpResponseRedirect(project.get_absolute_url())
def dele(): form = JoinForm() role_list=[] zu = Group.query.filter_by(groupname=form.name.data).first() if form.validate_on_submit(): if zu is not None: ren_list=zu.user.all() if g.user in ren_list: for rens in ren_list: role_list.append(rens.role[0]) role_list.remove(g.user.role[0]) g.user.group.remove(zu) db.session.add(g.user) db.session.commit() flash(u'你已从该群移出!') else: flash(u'操作无效,你不是该群成员!') return redirect(url_for('dele')) else: flash(u'请正确输入群名!') return redirect(url_for('dele')) return render_template('delete.html', title='Home', form=form, zu=zu)
def update(request, code): profile = check_profile(code) if not profile: messages.error(request, 'Your personal URL is incorrect, please reset your account or provide proper url') return redirect('index', m='Your invitation URL is not valid') from forms import JoinForm if request.method == 'POST': form=JoinForm(request.POST) if form.is_valid(): profile.first_name=form.cleaned_data['first_name'] profile.last_name=form.cleaned_data['last_name'] profile.unit=form.cleaned_data['unit'] profile.email=form.cleaned_data['email'] profile.save() keywords = __to_keywords(form.cleaned_data['keywords']) profile.keywords.clear(); for k in keywords: profile.keywords.add(k) profile.save() messages.info(request, 'Your profile has been updated') return redirect(homepage, code=code) keywords=profile.summary() form=JoinForm(initial={ 'first_name':profile.first_name, 'last_name':profile.last_name, 'unit':profile.unit, 'email':profile.email, 'key':code, 'keywords':keywords}) return render_to_response('researchers/update.html', {'profile':profile, 'form':form, 'key':code}, context_instance=RequestContext(request))
def home(request): try: refer_id = request.session['ref'] obj = Join.objects.get(id=refer_id) except: obj = None # print obj if request.method == 'POST': form = JoinForm(request.POST) if form.is_valid(): new_join = form.save(commit=False) new_join.ip_address = get_ip(request) new_join.ref_id = get_ref_id(request) if not obj == None: new_join.friend = obj # Every joined will be has an obj as a friend. new_join.save() return HttpResponseRedirect('/%s'% (new_join.ref_id)) else: form = JoinForm() context = {'form':form} template = 'home.html' return render(request, template, context)
def signup(): off = "y" signup_on = "y" # take form filed of JoinForm form = JoinForm() # check for request method POST if request.method == 'GET': return render_template("signup.html", form=form, signup_on=signup_on, off=off) # check for validate if not form.validate_on_submit(): return redirect(url_for("signup")) # +: check for user email does not include for class User inputs = form.email.data if User.query.get(inputs): alert = "danger" return render_template("signup.html", form=form, alert=alert, signup_on=signup_on, off=off) # commit class User to user data user_db = User(id=form.email.data, password=generate_password_hash(form.password.data)) db.session.add(user_db) db.session.commit() return redirect(url_for('index'))
def signup(): off="y" signup_on="y" # take form filed of JoinForm form = JoinForm() # check for request method POST if request.method=='GET': return render_template("signup.html",form=form,signup_on=signup_on,off=off) # check for validate if not form.validate_on_submit(): return redirect(url_for("signup")) # +: check for user email does not include for class User inputs=form.email.data if User.query.get(inputs): alert="danger" return render_template("signup.html",form=form,alert=alert,signup_on=signup_on,off=off) # commit class User to user data user_db=User( id=form.email.data, password=generate_password_hash(form.password.data) ) db.session.add(user_db) db.session.commit() return redirect(url_for('index'))
def join_group(): form = JoinForm() if form.validate_on_submit(): cur = mysql.connection.cursor() cur.callproc("JOINGROUP", [ session['username'], form.group_id.data, datetime.now(), ]) mysql.connection.commit() cur.close() flash(f' You have sucessfully joined {form.group_id.data}', 'success') return redirect(url_for('join_group')) cur = mysql.connection.cursor() cur.callproc("GETGROUP_INFO", [session['username']]) join_groups = cur.fetchall() cur.close() len_group = len(join_groups) print("groups: ", join_groups, len_group) return render_template('join_group.html', title='Join a Group', form=form, legend='Join An Existing Group', len_group=len_group, groups=join_groups)
def addgroup(tuple): display_info = [] info = tuple.split(",") searching = info[0] adding = info[2] time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') form = JoinForm() group = Group() group_info = group.search_group(searching) request_1 = Relation_control() if group_info is not []: for row in group_info: request_1.check_request(current_user.user_email, row["name"]) request_info = request_1.show_request(current_user.user_email) for item in group_info: for item2 in request_info: if item2["name"] == item["name"]: display_info.append(item2) if form.validate_on_submit(): search_result = request.form.get('searching', None) tuple = search_result + "," + adding + "," + adding return redirect( request.args.get('next') or url_for('addgroup', tuple=tuple)) if adding == "!@#$%": print("ignore") else: new_request = request_1.update_request(current_user.user_email, adding, time) i = 0 for item in display_info: if item["name"] == new_request["name"]: display_info[i] = new_request break else: i = i + 1 tuple = searching + "," + adding return render_template('addgroup.html', groups=display_info, form=form, tuple=tuple, dada=searching, user_info_global=user_info_global)
def search(): """Search Search for the successor node responsible for a given key. :param key: the key of the node which should be found. :returns: html page with node information, possible also with errors if the input is invalid. """ search_form = SearchForm() if search_form.validate_on_submit(): result_node, msg, count = node.find_successor( int(request.form.get('key')), node.key) if result_node is not None: output = "{0}:{1}, key={2}, msg={3}, hop count = {4}".format( result_node.ip, result_node.port, result_node.key, msg, count) else: output = msg flash(output, 'success') return redirect(url_for('home')) join_form = JoinForm() add_form = AddForm() return render_template('home.html', node=node, join_form=join_form, add_form=add_form, search_form=search_form)
def request_add_photon(): """Request add photon This endpoint will make the node search for the appropriate node of which the photon should be added to. If such a node is found without any error, the photon will be added to it. :param photon_id: the particle-io id of the photon that should be added to the network. :returns: html page with node information, and information about the operation. """ add_form = AddForm() if add_form.validate_on_submit(): photon_id = request.form.get('photon_id') if node.request_photon_add(photon_id): key = encode_key(photon_id) flash( 'Successfully added photon to the network, with key: ' + str(key), 'success') else: flash('Failed to add photon to the network', 'danger') return redirect(url_for('home')) join_form = JoinForm() search_form = SearchForm() return render_template('home.html', node=node, join_form=join_form, add_form=add_form, search_form=search_form)
def update_role(request, project_author, project_pk): user = request.user project = get_object_or_404(Project, pk=project_pk) membership = get_object_or_404(Membership, project=project, user=user) if request.method == 'POST': form = JoinForm(request.POST) if form.is_valid(): role = form.cleaned_data['role'] membership.role = role membership.save() else: user.message_set.create(message="Something was wrong with your form. Please note that your role description may not be longer than 120 characters. Here's the text you entered: %s" % role) return HttpResponseRedirect(project.get_absolute_url())
def update(request, code): profile = check_profile(code) if not profile: messages.error( request, 'Your personal URL is incorrect, please reset your account or provide proper url' ) return redirect('index', m='Your invitation URL is not valid') from forms import JoinForm if request.method == 'POST': form = JoinForm(request.POST) if form.is_valid(): profile.first_name = form.cleaned_data['first_name'] profile.last_name = form.cleaned_data['last_name'] profile.unit = form.cleaned_data['unit'] profile.email = form.cleaned_data['email'] profile.save() keywords = __to_keywords(form.cleaned_data['keywords']) profile.keywords.clear() for k in keywords: profile.keywords.add(k) profile.save() messages.info(request, 'Your profile has been updated') return redirect(homepage, code=code) keywords = profile.summary() form = JoinForm( initial={ 'first_name': profile.first_name, 'last_name': profile.last_name, 'unit': profile.unit, 'email': profile.email, 'key': code, 'keywords': keywords }) return render_to_response('researchers/update.html', { 'profile': profile, 'form': form, 'key': code }, context_instance=RequestContext(request))
def join(): server_error = None form = JoinForm() if form.validate_on_submit(): planning_name = request.form['planning'] password = request.form['password'] username = request.form['name'] planning = db.Planning.get(title=planning_name) if planning.password != password: server_error = "Password is incorrect for the selected planning meeting." else: stories = [] for story in planning.stories: story_id = story.id name = story.name response = requests.get(app.config['JIRA']['base_url'] + app.config['JIRA']['rest_issue'] + str(name) + "?fields=description,summary", auth=(app.config['JIRA']['user'], app.config['JIRA']['password'])) data = response.json() description = data["fields"]["description"] summary = data["fields"]["summary"] # TODO move this to the creation phase and add to database stories.append({ 'id': story_id, 'name': name, "description": description, "summary": summary }) return render_template('estimate_main.html', planning_title=planning_name, stories=stories, username=username) planning_list = select(p.title for p in db.Planning) return render_template('estimate_start.html', planning_list=planning_list, error=server_error, form=form)
def setup_account(key, token): """ :param key: :param token: :return: """ form = JoinForm() membership = utils.organization.membership_from_key_token(key, token) if membership is None: flash('Invalid or expired confirmation link', 'danger') return redirect(url_for('main.home')) if form.validate_on_submit(): utils.organization.confirm_user(membership.member, form.password.data) utils.organization.confirm_invite(membership) return redirect(url_for('main.home')) else: return render_template('main/setup.html', form=form, organization=membership.organization)
def join(request, code): """ TODO: After registring a user invitation should be disable. """ if not check_invitation(code): messages.error( request, 'Your personal URL is incorrect, please ask for new invitation or provide proper url' ) return redirect('index') from forms import JoinForm if request.method == 'POST': form = JoinForm(request.POST) if form.is_valid(): profile = Profile(first_name=form.cleaned_data['first_name'], last_name=form.cleaned_data['last_name'], unit=form.cleaned_data['unit'], email=form.cleaned_data['email'], key=generate_key()) profile.save() keywords = __to_keywords(form.cleaned_data['keywords']) profile.keywords.clear() for k in keywords: profile.keywords.add(k) profile.save() return redirect('homepage', code=profile.key) else: form = JoinForm(initial={'key': code}) return render_to_response( 'researchers/join.html', { 'form': form, 'key': code, # invitation code }, context_instance=RequestContext(request)) return render_to_response('researchers/join.html', {'form': form}, context_instance=RequestContext(request))
def showgroups(deletegroup): # deletegroup group = Group() if deletegroup == "None": print("haha") else: group.delete_quit_group(current_user.user_email, deletegroup) print("haha222") info = group.show_group_join(current_user.user_email) print(info) form = JoinForm() if form.validate_on_submit(): search_result = request.form.get('searching', None) search_result = search_result + ",1,!@#$%" return redirect( request.args.get('next') or url_for('addgroup', tuple=search_result)) return render_template('showgroups.html', groups=info, form=form, user_info_global=user_info_global)
def join(): if session.get('logged_in'): return redirect(url_for('index')) form = JoinForm() if form.validate_on_submit(): try: with pg_db.atomic(): user = User.create( username=form.username.data, password=md5((form.password.data).encode('utf-8')).hexdigest(), email=form.email.data, about_me='', join_date=datetime.now()) auth_user(user) return redirect(url_for('index')) except IntegrityError: flash('That username or email is already in use') return render_template('join.html', form=form, title='Join Us')
def join(request): valid = False if request.method == "POST": form = JoinForm(request.POST) if form.is_valid(): email = form.cleaned_data["email"] first_name = form.cleaned_data["first_name"] last_name = form.cleaned_data["last_name"] university = form.cleaned_data["university"] degree_subject = form.cleaned_data["degree_subject"] graduation_year = form.cleaned_data["graduation_year"] subject = "%s %s has requested to join Founder School" subject = subject % (first_name, last_name) message = """%s %s has requested to join Founder School\n \n Email: %s\n University: %s\n Degree subject: %s\n Graduation year: %s """ message = message % (first_name, last_name, email, university, degree_subject, graduation_year) from_email = "*****@*****.**" recipient_list = settings.REQUEST_TO_JOIN_EMAILS send_mail(subject, message, from_email, recipient_list, fail_silently=False) valid = True else: form = JoinForm() return render(request, "join.html", {"form": form, "valid": valid})
def join(): """Join Join the chord-network which the node with the provided ip and port is part of. :param ip: the ip-address of the node which should be joined. :param port: the port of the node which should be joined. :returns: html page with node information, possible also with errors if the input is invalid. """ join_form = JoinForm() if join_form.validate_on_submit(): join_ip = request.form.get('ip') join_port = request.form.get('port') node.join(join_ip, join_port) flash('Successfully join network', 'success') return redirect(url_for('home')) search_form = SearchForm() add_form = AddForm() return render_template('home.html', node=node, join_form=join_form, add_form=add_form, search_form=search_form)
def join(): form = JoinForm() if form.validate_on_submit(): s = Group.query.filter_by(groupname=form.name.data).first() user_role=g.user.role.all() if s is None: flash(u'此群未建立') else: ren_list=s.user.all() for ren in ren_list: if ren==g.user: flash(u'你在该组群,不需重新加入!') return redirect(url_for('join')) else: if user_role==[]: flash(u'请先编辑你的信息,再加入群组!') return redirect(url_for('join')) else: g.user.group.append(s) db.session.add(g.user) db.session.commit() flash(u'加入成功!') return render_template('join.html', form=form)
def home(): """Homepage Show all information about the node :returns: html page with node information """ join_form = JoinForm() add_form = AddForm() search_form = SearchForm() return render_template('home.html', node=node, join_form=join_form, add_form=add_form, search_form=search_form)
def game_t(game_id): game = Games.query.get_or_404(game_id) flag = 1 formpage = None if game.vacant != 0: if game.creator != current_user: flag = 0 if current_user.phone in game.members: formpage = LeaveForm() if formpage.validate_on_submit(): toreplace = ' | ' + current_user.name + ' Cel: ' + current_user.phone members = game.members.replace(toreplace, '') game.members = members new_vacant = game.vacant + 1 game.vacant = new_vacant db.session.commit() flash('You have leave!!!', 'success') return redirect(url_for('tennis')) else: formpage = JoinForm() if formpage.validate_on_submit(): members = game.members + ' | ' + current_user.name + ' Cel: ' + current_user.phone game.members = members new_vacant = game.vacant - 1 game.vacant = new_vacant db.session.commit() flash('You have join the team!!!', 'success') return redirect(url_for('tennis')) if game.creator == current_user: flag = 0 formpage = DeleteForm() if formpage.validate_on_submit(): slot = Slots.query.get_or_404(game.slot_id) slot.availability = 'True' flash('The game has been deleted!!!', 'success') db.session.delete(game) db.session.commit() return redirect(url_for('tennis')) return render_template('game.html', title='Update Game', formpage=formpage, flag=flag, game=game)
def team(team_id, sport): team = Teams.query.get_or_404(team_id) formpage = None flag = 1 link = 'http://127.0.0.1:5000/' + str(team_id) + sport + '/chat' if team.vacant != 0: if team.begginer != current_user: flag = 0 if current_user.phone in team.members: formpage = LeaveForm() if formpage.validate_on_submit(): toreplace = ' | ' + current_user.name + ' Cel: ' + current_user.phone members = team.members.replace(toreplace, '') team.members = members new_vacant = team.vacant + 1 team.vacant = new_vacant db.session.commit() flash('You have leave!!!', 'success') return redirect(url_for(sport)) else: formpage = JoinForm() if formpage.validate_on_submit(): members = team.members + ' | ' + current_user.name + ' Cel: ' + current_user.phone team.members = members new_vacant = team.vacant - 1 team.vacant = new_vacant db.session.commit() flash('You have join the team!!!', 'success') return redirect(url_for(sport)) if team.begginer == current_user: flag = 0 formpage = DeleteForm() if formpage.validate_on_submit(): flash('The team has been deleted!!!', 'success') db.session.delete(team) db.session.commit() return redirect(url_for(sport)) return render_template('team.html', title='Update Team', formpage=formpage, team=team, flag=flag, link=link)