Yii输入准确验证码却表明退步的消除办法,path与public帕特h的差异详解
前文已述,因为需要测试mysql的主从配置方案,所以要安装多个mysql。这次是在ubuntu
kylin 14.10上安装多个mysql 5.7.14。
前言
前言
系统环境:ubuntu kylin 14.10,64位系统
mysql版本:5.7.14社区版
mysql下载地址:,选择 Linux –
Generic,下载612.9M的mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
mysql官方安装文档:.按照官方安装文档进行即可,只是一些shell命令做了修改,对ubuntu来说,大部分命令都需要在前面增加sudo
在webpack模块化开发的过程中,发现webpack.config.js配置文件的输出路径总有一个path与publicPath,不解其意。
最近在做一个需求时,发现输入正确验证码,但是都提示验证码错误
shell> sudo groupadd mysql
shell> sudo useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> sudo tar -zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> sudo mv mysql-5.7.14-linux-glibc2.5-x86_64 mysql-5.7.14-linux-glibc2.5-x86_64-3306 #将mysql的目录改了一下名
shell> sudo ln -s mysql-5.7.14-linux-glibc2.5-x86_64-3306 mysql-3306
shell> cd mysql-3306
shell> sudo mkdir mysql-files
shell> sudo chmod 750 mysql-files
shell> sudo chown -R mysql:mysql .
shell> sudo cp support-files/my-default.cnf ./my.cnf #copy一份my.cnf
接着编辑my.cnf,打开basedir,datadir,port等项,按如下配置:
basedir = /usr/local/mysql-3306
datadir = /usr/local/mysql-3306/data
port = 3306
server_id = 11
然后开始初始化3306端口上的mysql:
shell> sudo bin/mysqld --defaults-file=/usr/local/mysql-3306/my.cnf --initialize --user=mysql
2016-07-29T15:38:48.896585Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-07-29T15:38:48.896672Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2016-07-29T15:38:48.896682Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2016-07-29T15:38:50.498675Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-07-29T15:38:50.890849Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-07-29T15:38:51.062752Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 8c708a13-55a2-11e6-835e-a0481ced538c.
2016-07-29T15:38:51.088854Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-07-29T15:38:51.090179Z 1 [Note] A temporary password is generated for root@localhost: pJLwjf%q;1t)
shell> sudo bin/mysql_ssl_rsa_setup --defaults-file=/usr/local/mysql-3306/my.cnf
Generating a 2048 bit RSA private key
.........+++
.......................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
..........+++
..............................................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
................................................+++
........................................+++
writing new private key to 'client-key.pem'
-----
shell> sudo chown -R root .
shell> sudo chown -R mysql data mysql-files
shell> sudo bin/mysqld_safe --user=mysql & #启动mysql,在后台运行
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
module.exports = {
output: {
path: path.resolve("./examples/dist"),
filename: "app.js",
publicPath: "What should I put here?"
}
}
最后追踪代码发现,如果 Model 在 save 前,单独做了 validate
验证,则在验证结束后,会重新生成验证码
2.开始登录mysql进行相关操作
正文
然后在我们 Model save
时,也会进行 validate
验证,验证时,验证码已经重新生成了,所以会匹配不上
/usr/local/mysql-3306> bin/mysql -uroot
-p
注意在执行bin/mysqld初始化时,在命令行最后的提示中给出了一个临时口令,输入之后即可登录。登录mysql之后,要求立即修改密码,否则不能进行任何操作。执行下面的命令修改’root’@’localhost’的密码:
官方解释
// 如果这里用到了验证码,就会出问题
$model = new Test();
$model->validate();
$model->save();
// 这样是正确的
$model = new Test();
// 把需要验证的 attribute 放进去,排除验证码字段
$model->validate(array('test1','test2'));
$model->save()
mysql> SET PASSWORD = PASSWORD('your new password');
mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
mysql> flush privileges;
publicPath: The output.path from the view of the Javascript / HTML
page.
我们可以看framework/web/widgets/captcha/CCaptchaAction.php
可以很容易就发现问题了
为了可以远程登录,增加一个’root’@’%’账号:
从JS/HTML页面来看的输出路径
<?php
class CaptchaAction extends CCaptchaAction
{
public function validate($input, $caseSensitive)
{
$code = $this->getVerifyCode();
$valid = $caseSensitive ? ($input === $code) : !strcasecmp($input, $code);
$session = Yii::app()->session;
$session->open();
$name = $this->getSessionKey() . 'count';
if (!Yii::app()->request->isAjaxRequest) {
$session[$name] = $session[$name] + 1;
}
// 这里会重新生成
if ($session[$name] > $this->testLimit && $this->testLimit > 0) {
$this->getVerifyCode(true);
}
return $valid;
}
}
复制代码 代码如下:
我的理解
总结
mysql> grant all privileges on *.* to ‘root’@’%’ identified by
‘your new password’ with grant option;
output.path 储存你所有输出文件的本地文件目录。(绝对路径)
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对脚本之家的支持。
3.按照上面的办法,继续解压安装mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz,并且配置为3307,3308,3309端口,就可以安装多个mysql了。
举个例子:
您可能感兴趣的文章:
- Yii框架实现的验证码、登录及退出功能示例
- Yii使用Captcha验证码的方法
- Yii2增加验证码步骤详解
- yii实现创建验证码实例解析
- yii2中添加验证码的实现方法
- Yii2简单实现给表单添加验证码的方法
- Yii2下点击验证码的切换实例代码
- Yii
2.0自带的验证码使用经验分享 - Yii2
如何在modules中添加验证码的方法 - Yii2框架实现登陆添加验证码功能示例