人人商城

forget.ctrl.php 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. $openid = $_W['openid'];
  8. $dos = array('reset', 'forget', 'verifycode');
  9. $setting = uni_setting($_W['uniacid'], array('uc', 'passport'));
  10. $uc_setting = $setting['uc'] ? $setting['uc'] : array();
  11. $register_mode = $setting['passport']['item'] ? $setting['passport']['item'] : 'random';
  12. $forward = url('mc');
  13. if(!empty($_GPC['forward'])) {
  14. $forward = './index.php?' . base64_decode($_GPC['forward']) . '#wechat_redirect';
  15. }
  16. if(!empty($_W['member']) && (!empty($_W['member']['mobile']) || !empty($_W['member']['email']))) {
  17. header('location: ' . $forward);
  18. exit;
  19. }
  20. if ($do == 'verifycode') {
  21. if($_W['ispost'] && $_W['isajax']) {
  22. $username = trim($_GPC['username']);
  23. $code = trim($_GPC['code']);
  24. load()->model('utility');
  25. if(!code_verify($_W['uniacid'], $username, $code)) {
  26. message('验证码错误', referer(), 'error');
  27. } else {
  28. pdo_delete('uni_verifycode', array('receiver' => $username));
  29. message('验证码正确', referer(), 'success');
  30. }
  31. }
  32. }
  33. if($do == 'reset') {
  34. if($_W['ispost'] && $_W['isajax']) {
  35. $username = trim($_GPC['username']);
  36. $password = trim($_GPC['password']);
  37. $repassword = trim($_GPC['repassword']);
  38. if ($repassword != $password) {
  39. message('密码输入不一致', referer(), 'error');
  40. }
  41. $sql = 'SELECT `uid`,`salt` FROM ' . tablename('mc_members') . ' WHERE `uniacid`=:uniacid';
  42. $pars = array();
  43. $pars[':uniacid'] = $_W['uniacid'];
  44. if(preg_match('/^\d{11}$/', $username)) {
  45. $type = 'mobile';
  46. $sql .= ' AND `mobile`=:mobile';
  47. $pars[':mobile'] = $username;
  48. } elseif(preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $username)) {
  49. $type = 'email';
  50. $sql .= ' AND `email`=:email';
  51. $pars[':email'] = $username;
  52. } else {
  53. message('用户名格式不正确', referer(), 'error');
  54. }
  55. $user = pdo_fetch($sql, $pars);
  56. if(empty($user)) {
  57. message('用户不存在', referer(), 'error');
  58. } else {
  59. $password = md5($password . $user['salt'] . $_W['config']['setting']['authkey']);
  60. mc_update($user['uid'], array('password' => $password));
  61. }
  62. message('找回成功', referer(), 'success');
  63. }
  64. }
  65. template('auth/forget');
  66. exit;