代码【注册】
; /*!/client/widget/login/login-form/login-form.js*/ define("passport:widget/login/login-form/login-form.js", function (require, exports, module) { "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function") } var $ = require("common:widget/lib/jquery/jquery"), handlebars = (require("common:widget/ui/utils/utils"), require("common:widget/lib/handlebars/handlebars")), MailSuggest = require("common:widget/ui/mailSuggest/mailSuggest"), glpbUtils = require("common:node_modules/glpb-components-common/src/index"), glpbCommon = require("common:node_modules/glpb-components-common/src/ValidateProvider/RRDValidator"), service = require("common:widget/ui/service/service-factory"), passportService = service.getService("passport"), LoginForm = function () { function LoginForm() { _classCallCheck(this, LoginForm); var source = $("#email-suggest-template").html(); this.template = handlebars.compile(source), this.$suggest = $('<div class="suggest" id="suggest" ></div>').appendTo($("body")), this.$pass = $("#J_pass_input"), this.suggest = new MailSuggest, this.$input = $("#j_username"), this.error = "账号密码不能为空"; var he = $(".login-ul").height(); this.validateCode = 195 == he ? !1 : !0 } return LoginForm.prototype.init = function () { var _this = this, that = this; this.suggestPostion(this.$suggest), $(".j-checkbox").on("click", function (e) { _this.checked(e) }), $("input[type=submit]").click(function () { _this.submitHandler() }), $("#randImage").click(function () { _this.changeRandCode() }), $("#randCode").keyup(function () { _this.validateRandCode() }), $("#j_username").on("keyup", function (e) { _this.emailKeyUp(e) }).on("keydown", function (e) { 13 == e.keyCode && e.preventDefault() }).on("focusout", function () { setTimeout(function () { that.$suggest.hide() }, 500) }), this.$suggest.on("mouseenter", "li", function () { $(this).addClass("cur") }).on("mouseleave", "li", function () { $(this).removeClass("cur").siblings().removeClass("cur") }).on("click", "li", function () { that.keyDownUp($("#j_username"), "enter"), that.$pass.trigger("focus") }), $("#J_pass_input").on("keyup", function (e) { _this.keyUpEnter(e) }), $("#randCode").on("keyup", function (e) { _this.keyUpEnter(e) }) }, LoginForm.prototype.keyUpEnter = function (e) { var that = e.target; $(that).parent().removeClass("orange"); var keyCode = e.keyCode; 13 == keyCode && this.submitHandler() }, LoginForm.prototype.checked = function (e) { var that = e.currentTarget; $(that).hasClass("j-checked") ? ($(that).removeClass("j-checked"), $(that).find("input").prop("checked", !1)) : ($(that).addClass("j-checked"), $(that).find("input").prop("checked", !0)) }, LoginForm.prototype.buttonLoading = function (num) { 1 == num ? ($(".submit .login-btn").val(""), $(".submit img").show()) : ($(".submit .login-btn").val("立即登录"), $(".submit img").hide()) }, LoginForm.prototype.submitHandler = function () { var _this2 = this; if (this.buttonLoading(1), this.validate()) return void this.buttonLoading(2); if (!this.validateCode) return this.error = "验证码错误", this.errorModal(2), void this.buttonLoading(2); var rememberme = $("#rememberme").is(":checked") ? "on" : ""; if ("on" != rememberme) return this.error = "请同意我们的服务协议", this.errorModal(-1), void this.buttonLoading(2); var that = this, password = glpbUtils.rsaCrypt($("#J_pass_input").val()), formData = { j_username: $("#j_username").val(), j_password: password, j_code: $("#randCode").val(), rememberme: "on", targetUrl: $("#targetUrl").val(), returnUrl: $("#returnUrl").val() }; passportService.doLogin(formData).then(function (res) { if (res.requestStatus === passportService.STATUS.ERROR) return _this2.buttonLoading(2), !0; var data = res.data; if (0 == data.status) location.href = data.data.jumpURL; else { data.data.isShowCaptcha ? ($(".input-hide").removeClass("input-hide"), $(".login-ul").animate({ height: "195px" }), that.changeRandCode()) : ($(".validate-image").addClass("input-hide"), $(".login-ul").animate({ height: "130px" })); var num = "", _status = data.status; "80016" == _status && (num = 1), "80003" == _status && (num = 0), "950001" == _status && (num = 2), that.error = data.message, that.errorModal(num), _this2.buttonLoading(2) } }) }, LoginForm.prototype.validateRandCode = function () { var params = { j_code: $("#randCode").val() }, that = this; passportService.captchaValidate(params).then(function (res) { if (res.requestStatus === passportService.STATUS.ERROR) return !0; var status = res.data.status; that.validateCode = 0 == status ? !0 : !1 }) }, LoginForm.prototype.changeRandCode = function () { var time = (new Date).getTime(); $("#randImage").attr("src", "/passport/index/captcha?time=" + time) }, LoginForm.prototype.validate = function () { var vali = glpbCommon.validate, userName = $("#j_username").val(), password = $("#J_pass_input").val(); if (!userName) return this.error = "手机号和邮箱不能为空", this.errorModal(0), !0; var isEmail = vali.isEmail(userName), isMobile = vali.isMobile(userName); return isEmail || isMobile ? password ? void 0 : (this.error = "密码不能为空", this.errorModal(1), !0) : (this.error = "请输入正确的邮箱地址或手机号码", this.errorModal(0), !0) }, LoginForm.prototype.errorModal = function (num) { $(".login-error").text(this.error), $(".login-error").fadeIn(2e3, function () { setTimeout(function () { $(".login-error").fadeOut(2e3) }, 2e3) }), num >= 0 && $(".login-ul li").eq(num).addClass("orange").siblings("li").removeClass("orange") }, LoginForm.prototype.suggestPostion = function (obj) { var $input = $("#j_username"), res = {}; res.left = $input.offset().left, res.top = $input.offset().top + $input.innerHeight(), obj.css({ left: res.left, top: res.top, absolute: "position" }) }, LoginForm.prototype.keyDownUp = function (obj, type) { var $cur = this.$suggest.find(".cur"), index = $cur.index(), len = this.$suggest.find("li").length; "down" == type ? (index++, index > len - 1 && (index = 0), this.$suggest.find("li").removeClass("cur").eq(index).addClass("cur")) : "up" == type ? (index--, 0 > index && (index = len - 1), this.$suggest.find("li").removeClass("cur").eq(index).addClass("cur")) : "enter" == type && ($("#j_username").val($cur.text()).blur(), this.$suggest.hide(), this.$pass.trigger("focus")) }, LoginForm.prototype.emailKeyUp = function (e) { $("#j_username").parent("li").removeClass("orange"), this.suggestPostion(this.$suggest); var email = $("#j_username").val(); switch (e.keyCode) { case 38: this.keyDownUp($(this), "up"); break; case 40: this.keyDownUp($(this), "down"); break; case 13: this.keyDownUp($(this), "enter"); break; default: if (!email.length) return void this.$suggest.hide(); var result = this.suggest.run(email); /^\d{1,}$/g.test(email) && (result.remove = !0); var html = this.template(result); this.$suggest.html(html).show().find("li").eq(0).addClass("cur") } }, LoginForm }(); module.exports = new LoginForm });; /*!/client/widget/login/register-form/register-form.js*/ define("passport:widget/login/register-form/register-form.js", function (require, exports, module) { "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function") } var $ = require("common:widget/lib/jquery/jquery"), utils = require("common:widget/ui/utils/utils"), glpbUtils = require("common:node_modules/glpb-components-common/src/index"), glpbCommon = require("common:node_modules/glpb-components-common/src/ValidateProvider/RRDValidator"), service = require("common:widget/ui/service/service-factory"), passportService = (service.getService("home"), service.getService("passport")), statistic = require("common:widget/ui/statistic/statistic"), utm = (require("common:widget/lib/gt/gt"), utils.utmsourceUtil), RegForm = function () { function RegForm() { _classCallCheck(this, RegForm), this.error = "不能为空", this.seconds = 60, this.sendTimes = 0, this.randCode = !1 } return RegForm.prototype.init = function (geetestData, isGeetest) { this.setInputVal(); var that = this; isGeetest ? this.initGt(geetestData) : $(".verification").on("click", function () { that.sendVerification() }), $(".reg-btn").on("click", function () { that.sendReg() }), $(".reg-ul li input").keyup(function (e) { that.hideOrangeLine(e) }), $(".rand-code").on("click", function () { that.rankCodeReload() }), this.initPvUv() }, RegForm.prototype.initPvUv = function () { var query = window.location.pathname, arr = query.split("/"); arr.reverse(); var login = arr[0], eventId = "PC_enter_login"; "register" == login && (eventId = "PC_enter_register"), statistic.eventRaw({ eventId: eventId }) }, RegForm.prototype.hideOrangeLine = function (e) { var that = e.target; $(that).parent("li").removeClass("orange") }, RegForm.prototype.sendReg = function () { var that = this; if (!(that.validateMoblie() || that.validateCode() || that.validatePassword() || that.validateMobileCode())) { that.buttonLoading(1); var password = glpbUtils.rsaCrypt($("#reg_password").val()), formData = { username: $("#reg_username").val(), password: password, mobileCode: $("#reg_verif").val(), intention: $("#intention").val(), type: $("#regRandCode").val(), id: $("#regId").val(), inviteCode: $("#regInviteCode").val(), registerSource: $("#regRegisterSource").val(), utmSource: $("#regPromotion").val(), agree: "on", platform: "PC", channel: "false" == window.tplConf._isWeCom ? "RRD" : "WE" }, utmSourceInUrl = utm.getUtmSourceBySearch(); utmSourceInUrl && (formData.utmSource = utmSourceInUrl); var utmCookieParams = utm.getAllUtmCookies(), urlSearchParams = utils.getSearchConf(), finalPostData = $.extend({}, utmCookieParams, urlSearchParams, formData); delete finalPostData.utm_source, passportService.doRegister(finalPostData).then(function (res) { if (res.requestStatus !== passportService.STATUS.SUCCESS) { var msg = res.data.message || "请求后端服务出错, 请稍后再试"; return that.zhugeFail(msg), Promise.reject(new Error(msg)) }! function () { var out = res.data; 0 === out.status ? statistic.eventRaw({ eventId: "pc_reg_success", extra: { url: location.href }, callback: function () { location.href = out.data.jumpURL } }) : 3310 === out.status ? (that.zhugeFail(out.message), that.error = out.message, that.errorModal(2), that.rankCodeReload(), that.buttonLoading(2)) : 3320 === out.status ? (that.zhugeFail(out.message), that.error = out.message, that.errorModal(0), that.rankCodeReload(), that.buttonLoading(2)) : 3330 === out.status ? (that.zhugeFail(out.message), that.error = out.message, that.errorModal(3), that.rankCodeReload(), that.buttonLoading(2)) : (that.zhugeFail(out.message), that.error = out.message, that.errorModal(-1), that.rankCodeReload(), that.buttonLoading(2)) }() }).caught(function (event) { that.zhugeFail(event.message), that.error = event.message, that.errorModal(-1), that.rankCodeReload(), that.buttonLoading(2) }) } }, RegForm.prototype.zhugeFail = function (mess) { statistic.event({ eventId: "pc_reg_failed", extra: { "失败原因": mess } }) }, RegForm.prototype.buttonLoading = function (num) { 1 == num ? ($(".reg-submit .reg-btn").val(""), $(".reg-submit img").show()) : ($(".reg-submit .reg-btn").val("注册领红包"), $(".reg-submit img").hide()) }, RegForm.prototype.setInputVal = function () { var urlSearchParams = utils.getSearchConf(), promotion = urlSearchParams.utm_source || urlSearchParams.utmSource || null, utm = utils.utmsourceUtil; null == promotion && (promotion = utm.getCookie("promotion") || utm.getCookie("utmSource")), null != promotion && promotion.match("[-a-zA-Z0-9?=_/]{1,32}") ? utm.setCookie("promotion_source", promotion, 365) : promotion = utm.getCookie("promotion_source"); var id = utm.getId(), inviteCode = utm.getInviteCode(), getRegisterSource = utm.getRegisterSource(); $("#regRegisterSource").val(getRegisterSource), $("#regId").val(id), $("#regPromotion").val(promotion), $("#regInviteCode").val(inviteCode), $("#intention").val("LENDER") }, RegForm.prototype.validateMoblie = function () { var vali = glpbCommon.validate, userName = $("#reg_username").val(); if (!userName) return this.error = "手机号不能为空", this.errorModal(0), !0; var isMobile = vali.isMobile(userName); return isMobile ? void 0 : (this.error = "请输入正确的手机号码", this.errorModal(0), !0) }, RegForm.prototype.validateMobileCode = function () { var agree = $(".reg-agree .j-checkbox").hasClass("j-checked"); return agree ? void 0 : (this.error = "请同意我们的服务协议", this.errorModal(-1), !0) }, RegForm.prototype.validateCode = function () { var randCode = $("#reg_verif").val(); return randCode ? 4 != randCode.length ? (this.error = "手机验证码必须是4位数", this.errorModal(2), !0) : void 0 : (this.error = "手机验证码不能为空", this.errorModal(2), !0) }, RegForm.prototype.rankCodeReload = function () { var time = (new Date).getTime(); $("#reg-rand-image").attr("src", "/passport/index/captcha?time=" + time), this.randCode = !1 }, RegForm.prototype.setIntervalFun = function () { var time = 60, dom = $(".verification"); dom.addClass("is_send").text("重新发送(" + time + ")"), dom.removeClass("is_validate"); var timer = setInterval(function () { time--, 0 >= time ? (dom.text("重新发送").removeClass("is_send"), dom.addClass("is_validate"), clearInterval(timer)) : dom.text("重新发送(" + time + ")") }, 1e3) }, RegForm.prototype.sendGeetestVerification = function (verifData) { var that = this; $(".verification").hasClass("is_send") || that.validateMoblie() || (passportService.sendRegisterSms(verifData).then(function (res) { var out = res.data; if (res.requestStatus === passportService.STATUS.SUCCESS) { if (0 == out.status) return that.setIntervalFun(), void that.sendTimes++; that.error = out.message, that.errorModal(-1) } }).caught(function () { that.error = "服务器异常,请稍后再试", that.errorModal(-1) }), statistic.eventRaw({ eventId: "PC_click_get_message" })) }, RegForm.prototype.sendVerification = function () { var that = this; if ($(".verification").hasClass("is_validate") && !that.validateMoblie()) { var rand = $("#reg_RandCode").val(), verifData = { mobile: $("#reg_username").val() }; verifData.channel = "RRD", "true" == window.tplConf._isWeCom && (verifData.channel = "WE"), rand && (verifData.imgCode = rand), passportService.sendRegisterSms(verifData).then(function (res) { var out = res.data; return res.requestStatus !== passportService.STATUS.SUCCESS ? Promise.reject(new Error("请稍候重试!")) : 0 == out.status ? (that.setIntervalFun(), void that.sendTimes++) : void("3230" == out.status ? ($(".rand_code_show").show(), that.error = out.message, that.errorModal(1)) : "3240" == out.status ? (that.rankCodeReload(), that.error = "验证码不正确", that.errorModal(1)) : (that.error = out.message, that.rankCodeReload(), that.errorModal(-1))) }).caught(function () { that.rankCodeReload(), that.error = "服务器异常,请稍后再试", that.errorModal(-1) }), statistic.eventRaw({ eventId: "PC_click_get_message" }) } }, RegForm.prototype.validatePassword = function () { var password = $("#reg_password").val(), passw = /^[a-zA-Z]{8,16}$|^[0-9]{8,16}$|^[~!@#$%^&*._]{8,16}$/.test(password), pw = /^[0-9A-Za-z~!@#$%^&*._]{8,16}$/.test(password); return !pw || passw ? (this.error = "密码为8~16位数字、字母或符号组合", this.errorModal(3), !0) : void 0 }, RegForm.prototype.validateRandCode = function () { var params = { j_code: $("#randCode").val() }, that = this; passportService.captchaValidate(params).then(function (res) { if (res.requestStatus === passportService.STATUS.ERROR) return !0; var status = res.data.status; that.validateCode = 0 == status ? !0 : !1 }) }, RegForm.prototype.initGt = function (geetestData) { initGeetest({ gt: geetestData.gt, challenge: geetestData.challenge, offline: !geetestData.success, new_captcha: geetestData.new_captcha, product: "bind", width: "300px", pure: 1 }, this.handler.bind(this)) }, RegForm.prototype.handler = function (captchaObj) { var that = this; captchaObj.onReady(function () { $("#wait").hide() }), captchaObj.onNextReady(function () { $(".loading-img").hide() }), captchaObj.onClose(function () { $(".loading-img").hide() }), captchaObj.onError(function () { $(".loading-img").hide(), captchaObj.reset() }), captchaObj.onSuccess(function () { $(".loading-img").hide(); var result = captchaObj.getValidate(); if (!result) return that.error = "请完成验证", void that.errorModal(-1); var channel = "true" == window.tplConf._isWeCom ? "WE" : "RRD", verifData = { channel: channel, mobile: $("#reg_username").val(), geetest_challenge: result.geetest_challenge, geetest_validate: result.geetest_validate, geetest_seccode: result.geetest_seccode }; that.sendGeetestVerification(verifData) }), $(".verification").on("click", function () { if (!that.validateMoblie()) { var isValidate = $(".verification").hasClass("is_validate"); isValidate && ($(".loading-img").show(), captchaObj.verify()) } }) }, RegForm.prototype.errorModal = function (num) { $(".reg-error").text(this.error), $(".reg-error").fadeIn(2e3, function () { setTimeout(function () { $(".reg-error").fadeOut(2e3) }, 2e3) }), num >= 0 && $(".reg-ul li").eq(num).addClass("orange").siblings("li").removeClass("orange") }, RegForm }(); module.exports = new RegForm });