首页/ AI 技能 / @skilllib/skill-2014279394611638274
Skill站外收录 @skilllib/skill-2014279394611638274

wheels-auth-generator

自动生成具备邮箱验证、密码强度校验与唯一性约束的用户模型,集成安全密码哈希与登录认证逻辑,并配套会话控制器实现登录登出流程,支持通过过滤器对受保护路由进行自动鉴权拦截。

0.0 (0) 545 次安装 原作者 编程导航
收录于 2026-01-22
软件开发 AI 技能

Skills.MD

# Wheels Auth Generator ## When to Use This Skill Activate when: - User requests authentication/login system - User wants user registration - User mentions: auth, login, logout, session, password, signup ## User Model with Authentication ```cfm component extends="Model" { function config() { validatesPresenceOf(property="email,password"); validatesUniquenessOf(property="email"); validatesFormatOf( property="email", regEx="^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$" ); validatesLengthOf(property="password", minimum=8); validatesConfirmationOf(property="password"); beforeSave("hashPassword"); } private function hashPassword() { if (structKeyExists(this, "password") && len(this.password) && !isHashed(this.password)) { this.password = hash(this.password, "SHA-512"); } } private boolean function isHashed(required string password) { return len(arguments.password) == 128; } public any function authenticate(required string email, required string password) { var user = this.findOne(where="email = '#arguments.email#'"); if (!isObject(user)) return false; var hashedAttempt = hash(arguments.password, "SHA-512"); return (user.password == hashedAttempt) ? user : false; } } ``` ## Sessions Controller ```cfm component extends="Controller" { function new() { // Show login form } function create() { var user = model("User").authenticate( email=params.email, password=params.password ); if (isObject(user)) { session.userId = user.id; flashInsert(success="Welcome back!"); redirectTo(controller="home", action="index"); } else { flashInsert(error="Invalid email or password"); renderPage(action="new"); } } function delete() { structDelete(session, "userId"); flashInsert(success="You have been logged out"); redirectTo(controller="home", action="index"); } } ``` ## Authentication Filter ```cfm // In any controller requiring authentication function config() { filters(through="requireAuth"); } private function requireAuth() { if (!structKeyExists(session, "userId")) { flashInsert(error="Please log in"); redirectTo(controller="sessions", action="new"); } } ``` --- **Generated by:** Wheels Auth Generator Skill v1.0

评论 0

还没有评论,来抢沙发。