我有FOSUser,现在正在尝试添加Google / Facebook注册,这意味着我仍将使用常规FOSUser设置来注册用户。
我知道有关HWIOAuthBundle的信息,但我不愿意添加其他捆绑软件。在我已经做完所有重写之后,已经对FOS捆绑包本身有了重新的思考。
使用来自Google的信息创建用户时,我当然会收到密码字段不能为空的错误。
这是在我的控制器中创建用户的功能:
private function registerUser($payload) {
$user = $this->userManager->createUser();
$user->setEmail($payload['email']);
$user->setUsername($payload['given_name'] . '-' . mt_rand()); // temporary username
$this->userManager->updateUser($user);
}
看着this SO question,我将密码字段添加到了修改后的用户实体中,但是Doctrine:migration没有捕获到它:
/**
* @ORM\Entity
* @ORM\Table(name="`user`")
*/
class User extends BaseUser
{
.....
/**
* @ORM\Column(type="string", name="password", nullable=true)
*/
protected $password;
我可能走错了路,在这种情况下,我感谢任何指导。
答案 0 :(得分:0)
我有一个linkedin登录/ Oauth。我只是设置了一个随机密码。他们无法登录,因为我什至都不知道,但是可以在确认电子邮件后重置它。
$user = new User();
$user->addRole($xyz->getRoleType());
$user->setUsername($xyz->getUsername());
$user->setEmail($xyz->getEmail());
// encode a random password, manually
$plainPassword = base64_encode(random_bytes(16));
$encodedPassword = $this->get('security.password_encoder')
->encodePassword($user, $plainPassword);
$user->setPassword($encodedPassword);
$user->setEnabled(true); // we have to enable the user to let them login again
$em->persist($user);
答案 1 :(得分:0)
这有点晚了,但是以防万一有人在寻找答案,可以通过教义的AttributeOverrides完成:
const setFormattedAmount = (value: string) => {
if (value && !isNaN(parseFloat(value))) {
//format the input value to have no commas
const inputValue = value.split(',').join('');
//reformat the string with commas in the correct positions
const amountString = new Intl.NumberFormat().format(parseFloat(inputValue));
setAmount(amountString);
} else {
setAmount('');
}
};