def reqChangePasswd(): found = False hostname = socket.gethostname() email = request.form['email'] obj = "[Easy Rash]restore password" body = "<p>to restore your password please click the link below<p>" data = getData("easyrash/users/users.json") req_file = getData("easyrash/requestSetPwd.json") for key in data: if (email == data[key]['email']): random_code = genRandom() for i in range(len(req_file)): if (req_file[i]['mail'] == email): req_file[i]['id'] = random_code found = True break if (found == False): req = {'mail': email, 'id': random_code} req_file.append(req) modifyData(req_file, 'easyrash/requestSetPwd.json') link = "<a href='http://" + hostname + ".cs.unibo.it:10000/api/verifyIDPWD/" + str( random_code ) + "' target='_blank'>" + hostname + ".cs.unibo.it:10000/api/verifyIDPWD/" + str( random_code) + "</a>" sendMail(obj, link, email, body) return "Sent" abort(409)
def restorePassword(): pwd = request.form["passwd"] logged = False #pwd = md5_crypt.encrypt(dec_pwd) data = getData('easyrash/users/users.json') if (hasattr(flask_login.current_user, 'id')): mail = flask_login.current_user.id old_pwd = request.form["old_passwd"] logged = True else: mail = request.form["mail"] req_file = getData("easyrash/requestSetPwd.json") for i in range(len(req_file)): if (req_file[i]['mail'] == mail): req_file.pop(i) modifyData(req_file, 'easyrash/requestSetPwd.json') for key in data: if (data[key]["email"] == mail): if (logged and md5_crypt.verify(old_pwd, data[key]['pass']) == False): print("control password") return (403) data[key]["pass"] = md5_crypt.encrypt(pwd) modifyData(data, "easyrash/users/users.json") return render_template("login.html") print("bad") abort(400)
def userInfoAdvanced(): user = flask_login.current_user.id advanced_info = { 'chair': [], 'author': [], 'reviewer': {}, 'number_reviewers': {} } user_key = searchUserInfo(user)['key'] users_data = getData('easyrash/events/events.json') for conf in users_data: for chair in conf['chairs']: if (chair == user_key): chair_obj = getSubmissionsInConf(conf['acronym']) advanced_info['chair'].append(chair_obj) for article in conf['submissions']: advanced_info['number_reviewers'].update( {article['url']: len(article['reviewers'])}) for article in conf['submissions']: for author in article['authors']: if (author == user_key): advanced_info['author'].append(article['title']) for reviewer in article['reviewers']: if (reviewer == user_key): advanced_info['reviewer'].update( {article['url']: article['title']}) basic_info = searchUserInfo(user)['user_data'] info = dict() info.update(advanced_info) info.update(basic_info) return jsonify(info)
def getSubmissionsInConf(conf): events = getData('easyrash/events/events.json') submissions = [] for conference in events: if conference['acronym'] == conf: for submission in conference['submissions']: submissions.append(submission['url']) obj = {'acronym': conf, 'submissions': submissions} return obj
def reqSignup(): found = False hostname = socket.gethostname() email = request.form['email'] nome = request.form['nome'][0].upper() + request.form['nome'][1:] cognome = request.form['cognome'][0].upper() + request.form['cognome'][1:] enc_passwd = request.form['passwd'] sex = request.form['sex'] passwd = md5_crypt.encrypt(enc_passwd) obj = "[Easy Rash]confirm registration" body = "<p>to confirm your registration please click the link below<p>" data = getData("easyrash/users/users.json") req_file = getData("easyrash/requestSignup.json") random_code = genRandom() for key in data: if (email == data[key]['email']): abort(409) for i in range(len(req_file)): if (req_file[i]['email'] == email): req_file[i]['id'] = random_code found = True break if (found == False): short_id = cognome[0].upper() + nome[0].upper() + sex[0].upper() + str( random_code) #prima lettera cognome, prima lettera, nome sesso req = { 'email': email, 'given_name': nome, 'family_name': cognome, 'sex': sex, 'pass': passwd, 'id': random_code, 'comment_id': short_id } req_file.append(req) modifyData(req_file, 'easyrash/requestSignup.json') link = "<a href='http://" + hostname + ".cs.unibo.it:10000/api/confReg/" + str( random_code ) + "' target='_blank'>" + hostname + ".cs.unibo.it:10000/api/confReg/" + str( random_code) + "</a>" sendMail(obj, link, email, body) return "Sent"
def confirmRegistration(id_req): ret = searchId(id_req, "easyrash/requestSignup.json") id_found = ret[0] new_user = ret[1] if (id_found == "OK"): req_file = getData("easyrash/requestSignup.json") for i in range(len(req_file)): if (req_file[i]['id'] == new_user['id']): req_file.pop(i) new_user.pop('id', 0) obj = { new_user["given_name"] + " " + new_user["family_name"] + " " + "<" + new_user["email"] + ">": new_user } data = getData('easyrash/users/users.json') data.update(obj) modifyData(data, "easyrash/users/users.json") modifyData(req_file, "easyrash/requestSignup.json") return redirect('/login') else: abort(409)
def searchUserArticles(mail): array_articles = [] user_key = searchUserInfo(mail)['key'] events = getData('easyrash/events/events.json') for conference in events: articles = conference['submissions'] for info in articles: authors = info['authors'] for name in authors: if (name == user_key): array_articles.append(info) obj_articles = {'user_articles': array_articles} return obj_articles
def lockSupport(mode, article): if (mode == "lock"): control = False locked = True elif(mode == "unlock"): control = True locked = False else: return 500 index = 0 user = flask_login.current_user.id user_key = searchUserInfo(user)['key']; mutex.acquire() if(mutex.locked() == False): return 500 # non dovresti essere qui, questo è male lock_data = getData('easyrash/lock.json') users_data = getData('easyrash/events/events.json') for conf in users_data: for article_ in conf['submissions']: if article_["url"] == article: for reviewer in article_["reviewers"]: if reviewer == user_key: for current in lock_data: if article == current['id']: if current['locked'] == control: lock_data[index]['locked'] = locked modifyData(lock_data, 'easyrash/lock.json') mutex.release() return 200 else: mutex.release() return 400 index = index + 1 mutex.release() return 400 mutex.release() return 404 # se non c'è l'articolo allora not found, controllo di sicurezza
def getConferences(user): conf_obj = getData('easyrash/events/events.json') data = [] found = False for key in conf_obj: for reviewer in key['pc_members']: if user + ">" == reviewer.split("<")[1]: found = True for chair in key['chairs']: if user + ">" == chair.split("<")[1]: found = True if found: data.append(key) found = False conferences = {'conferences': data} return conferences
def login(): if (flask_login.current_user.is_authenticated): return redirect('/') else: if (request.method == 'GET'): return render_template('login.html') email = request.form['email'] enc_passwd = request.form['passwd'] data = getData("easyrash/users/users.json") for key in data: if (email == data[key]['email'] and md5_crypt.verify(enc_passwd, data[key]['pass'])): user = User() user.id = email flask_login.login_user(user, remember=True) return jsonify(data[key]) abort(401) # se nel for non trova email e password validi