本文整理汇总了PHP中Model\User::setPassword方法的典型用法代码示例。如果您正苦于以下问题:PHP User::setPassword方法的具体用法?PHP User::setPassword怎么用?PHP User::setPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model\User
的用法示例。
在下文中一共展示了User::setPassword方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insertUpdateProcessing
public function insertUpdateProcessing($em, $passwordEncoder, $data, $id)
{
$update = !is_null($id);
try {
$em->beginTransaction();
if ($update) {
$user = $em->find('Model\\User', $id);
} else {
$user = new User();
}
$user->setUsername($data['username']);
//Regenerate salt and update password only if a new password is provided
if (isset($data['password']) && strlen($data['password']) > 8 && strlen($data['password']) < 1024) {
//Prepare salt
// $salt = base64_encode(mcrypt_create_iv(ceil(0.75 * 32), MCRYPT_DEV_URANDOM));
$salt = uniqid("", true);
$user->setSalt($salt);
//Encrypt password
$password = $passwordEncoder->encodePassword($data['password'], $user->getSalt());
$user->setPassword($password);
}
$user->setName($data['name']);
$user->setSurname($data['surname']);
$user->setEmail($data['email']);
$user->setPhone($data['phone']);
$user->setAddress($data['address']);
$user->setCap($data['cap']);
$user->setCity($data['city']);
$user->setProvince($data['province']);
$user->setCountry($data['country']);
//Prepare roles string
$roles = array();
if (isset($data['roles'])) {
foreach ($data['roles'] as $roleString => $val) {
$roles[] = new Role($roleString);
}
}
$user->setRoles($roles);
//Prepare accountExpiration DateTime object
$accountExpiration = new \DateTime($data['accountExpiration'], new \DateTimeZone('Europe/Rome'));
$user->setAccountExpiration($accountExpiration);
$enabled = isset($data['enabled']);
$user->setEnabled($enabled);
//Prepare credentialsExpiration DateTime object
$credentialsExpiration = new \DateTime($data['credentialsExpiration'], new \DateTimeZone('Europe/Rome'));
$user->setCredentialsExpiration($credentialsExpiration);
if ($update) {
$em->merge($user);
} else {
$em->persist($user);
}
$em->flush();
$em->commit();
} catch (\Exception $e) {
$em->rollback();
throw $e;
}
return $user->getId();
}
示例2: registerUser
public function registerUser()
{
$user = new User();
$user->setEmail($this->request_body->email);
$user->setPassword(md5($this->request_body->password));
$user->save();
$token = new AccessToken();
$token->setTokenContent(uniqid());
$token->setUser($user);
$token->save();
return array('user' => $user->toArray(), 'token' => $token->toArray());
}
示例3: register
/**
* @JSON
*/
public function register()
{
$result = array('error' => 1, 'message' => '注册失败');
$email = strtolower(trim($_POST['r_email']));
$userName = trim($_POST['r_user_name']);
$passwd = trim($_POST['r_passwd']);
$repasswd = trim($_POST['r_passwd2']);
$inviteCode = trim($_POST['r_invite']);
$invite = Invite::getInviteByInviteCode($inviteCode);
//校验 invite 是否可用
if ($invite->status != 0 || $invite == null || empty($invite)) {
$result['message'] = '邀请码不可用';
} else {
if ($repasswd != $passwd) {
$result['message'] = '两次密码输入不一致';
} else {
if (strlen($passwd) < 6) {
$result['message'] = '密码太短,至少8字符';
} else {
if ($chkEmail = Utils::mailCheck($email)) {
$result['message'] = $chkEmail;
} else {
$user = new User();
$user->email = $email;
if ($userName == null) {
$userName = $email;
}
$userCount = Stats::countUser();
$user->nickname = $userName;
// LEVEL 从数据库中获取
$custom_transfer_level = json_decode(Option::get('custom_transfer_level'), true);
// 定义邀请码套餐与流量单位
$transferNew = Utils::GB * intval($custom_transfer_level[$invite->plan]);
$user->transfer = $transferNew;
$user->invite = $inviteCode;
$user->plan = $invite->plan;
// 将邀请码的账户类型设定到注册用户上.
$user->regDateLine = time();
$user->lastConnTime = $user->regDateLine;
$user->sspwd = Utils::randomChar();
$user->payTime = time();
// 注册时支付时间
$user_test_day = Option::get('user_test_day') ?: 7;
$user->expireTime = time() + 3600 * 24 * intval($user_test_day);
// 到期时间
$mailVerify = Option::get('mail_verify');
// 邮件验证是否开启
if ($userCount > 0 && $mailVerify) {
$user->enable = 0;
// 停止账户
$code = Utils::randomChar(10);
$forgePwdCode['verification'] = $code;
$forgePwdCode['time'] = time();
$user->forgePwdCode = json_encode($forgePwdCode);
$mailer = Mailer::getInstance();
$mailer->toQueue(false);
$mail = new Mail();
$mail->to = $user->email;
$mail->subject = '[' . SITE_NAME . '] 新账户注册邮箱校验';
$mail->content = Option::get('custom_mail_verification_content');
$params = ['code' => $code, 'nickname' => $user->nickname, 'email' => $user->email, 'useTraffic' => Utils::flowAutoShow($user->flow_up + $user->flow_down), 'transfer' => Utils::flowAutoShow($user->transfer), 'expireTime' => date('Y-m-d H:i:s', $user->expireTime), 'REGISTER_URL' => base64_encode($user->email . "\t" . $forgePwdCode['verification'] . "\t" . $forgePwdCode['time'])];
$mail->content = Utils::placeholderReplace($mail->content, $params);
$mailer->send($mail);
} else {
$user->enable = 1;
// 第一个账户,默认设定为启用
$user->forgePwdCode = null;
}
$user->port = Utils::getNewPort();
// 端口号
$user->setPassword($passwd);
$user->save();
$invite->reguid = $user->uid;
$invite->regDateLine = $user->regDateLine;
$invite->status = 1;
// -1过期 0-未使用 1-已用
$invite->inviteIp = Utils::getUserIP();
$invite->save();
if (null != $user->uid && 0 != $user->uid) {
$result['error'] = 0;
$result['message'] = '注册成功';
}
if ($mailVerify) {
$result['message'] .= ',您需要验证邮箱后才能使用本站功能。';
}
Logger::getInstance()->info('user [' . $user->email . '] register success');
}
}
}
}
return $result;
}