def user_detail_info(): name = request.values.get('name') #name不能為空 if name == "": return jsonify({'message': '資料不得為空'}) user_detail_info_list = [] if len(user.get_user_info_by_name(name)) == 0: return jsonify({'message': '此人不存在'}) for i in user.get_user_info_by_name(name): course_name_list = [] course_list = i['course_list'] for j in course_list: course_name_list.append( course.get_course_info(j)['name']) #course_list中的id應該不會有錯 user_detail_info_list.append({ 'course_list': i['course_list'], 'email': i['email'], 'name': i['name'], 'phone': i['phone'], 'role': i['role'], 'user_id': i['user_id'], 'course_name_list': course_name_list }) return jsonify(user_detail_info_list)
def post(self): username = self.get_argument("username") email = self.get_argument("email") password = self.get_argument("password") confirm_password = self.get_argument("confirm_password") form = SignupForm(self.request.arguments) signup_error = signup_validation(self.session, username) if form.validate(): if signup_error == "": signup(self.session, username, email, password, self.get_ip()) user_info = get_user_info_by_name(self.session, username) self.set_cookies(user_info) self.redirect("/") else: self.render("signup.html", username=None, group=None, form=form, db_error=signup_error) else: self.render("signup.html", username=None, group=None, form=form, db_error=None)
def post(self): username = self.get_argument("username") password = self.get_argument("password") login_error = login_validation(self.session, username, password) form = LoginForm(self.request.arguments) if form.validate(): if login_error == "": user_info = get_user_info_by_name(self.session, username) update_last_visit(self.session, username, self.get_ip()) self.set_cookies(user_info) self.redirect("/") else: self.render("login.html", username=None, group=None, form=form, db_error=login_error) else: self.render("login.html", username=None, group=None, form=form, db_error=None)
def user_update_validation(session, user_info, current_uid, arguments): if (get_user_info_by_name(session, arguments['username']) is not None) \ and (user_info.username != arguments['username']): return _("Username already exist!") if str(user_info.id) == current_uid: return _("Can not edit your own information") return ""
def delete_cs_course_info(): course_id = request.values.get('course_id') course_info = course.get_course_info(course_id) #course_id不得為空 if course_id == "": return jsonify({'message': '資料不得為空'}) #把student的course_list中的該course刪除 for i in course_info['student_list']: temp = user.get_user_info(i)['course_list'] temp.remove(course_id) user.update_user({'user_id': i}, {'course_list': temp}) #把teacher的course_list中的該course刪除 teacher_info = user.get_user_info_by_name(course_info['teacher']) temp = teacher_info[0]['course_list'] #老師沒有名字重複的問題 temp.remove(course_id) user.update_user({'user_id': teacher_info[0]['user_id']}, {'course_list': temp}) courseid = {'course_id': course_id} course.delete_course(courseid) return jsonify({'0': 0}) #之後redirect