|
@@ -269,23 +269,34 @@ async def send_reset_pwd(user_id,email):
|
|
|
code = str(time.time()).replace('.','')
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
|
db['reset_pw_code'].insert({'code':code,'user_id':user_id,'email':email})
|
|
|
- msg = '請至點擊網址以重設密碼 : https://www.choozmo.com:8887/reset_password?code='+code
|
|
|
+ msg = '請至點擊網址以重設密碼 : https://www.choozmo.com:8887/reset_pwd_page 通行碼為 '+ code
|
|
|
+ print(msg)
|
|
|
msg =msg.encode(encoding='utf-8')
|
|
|
- user_dict = next(iter(db.query('SELECT * FROM users where id ="'+str(user_id)+'"')))
|
|
|
+ print(msg)
|
|
|
+ print(type(user_id))
|
|
|
+ if int(user_id) != -1:
|
|
|
+ print('print at first place')
|
|
|
+ print(user_id)
|
|
|
+ user_dict = next(iter(db.query('SELECT * FROM users where id ="'+str(user_id)+'"')))
|
|
|
+ else:
|
|
|
+ user_id = util.user.get_id_by_email(email)
|
|
|
+ print(user_id)
|
|
|
+ user_dict = next(iter(db.query('SELECT * FROM users where id ="'+str(user_id)+'"')))
|
|
|
mailer.send(msg, user_dict['email'])
|
|
|
return {'msg':'ok'}
|
|
|
|
|
|
@app.post('/reset_pwd')
|
|
|
async def reset_password(req :models.reset_pwd):
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
|
+ print(req.code)
|
|
|
veri_obj = next(iter(db.query('SELECT * FROM reset_pw_code where code ="'+str(req.code)+'"')))
|
|
|
+ print(veri_obj['user_id'])
|
|
|
+ user_id = util.user.get_id_by_email(veri_obj['email'])
|
|
|
+ print(user_id)
|
|
|
+ db.query('UPDATE users SET password = '+'"'+get_password_hash(req.password)+'" where id ='+str(user_id))
|
|
|
+
|
|
|
if veri_obj != None:
|
|
|
db['reset_pw_code'].delete(code=req.code)
|
|
|
- if veri_obj['user_id'] == -1:
|
|
|
- val = db.query('UPDATE users SET password = '+'"'+get_password_hash(req.password)+'" where id ='+str(veri_obj['user_id']))
|
|
|
- else:
|
|
|
- user_id = user.get_id_by_email(veri_obj['email'])
|
|
|
- val = db.query('UPDATE users SET password = '+'"'+get_password_hash(req.password)+'" where id ='+str(user_id))
|
|
|
return {"msg": "ok"}
|
|
|
|
|
|
@app.get("/gen_avatar")
|