register.js 5.21 KB
Newer Older
manxiaoqiang committed
1 2 3 4 5
(function(){
     angular.module("app.login")
        .controller("registerCtrl",["$scope","UtilService","$http","$interval",registerCtrl]);

    function registerCtrl($scope,UtilService,$http,$interval){
6
        io.init(UtilService.getTKAppkey());
yangfangfang committed
7

manxiaoqiang committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
        //loading加载
        $scope.showLoading = function(){
            document.getElementById("sysLoad").style.display = "block";
        }
        $scope.hideLoading = function(){
            document.getElementById("sysLoad").style.display = "none";
        }
        $http.get("/data/channel.json").success(function(data){
            $scope.channelNames = data;
        })
        $scope.hasReged = false;
        $scope.save = function(){
            var par = {
                email: $scope.email,
                password: $scope.password,
                company: $scope.company,
                name: $scope.username,
                phone: $scope.phone,
                wechat: $scope.wechat,
                qq: $scope.qq
            };
            var verPar = {
                email: {
                    key: 'email',
                    max:48,
                    val: par.email,
                    txt:"邮箱最长48位"
                },
                password: {
                    key: 'pwd',
                    val: par.password
                },
                crmpwd: {
                    key: 'pwd',
                    val: $scope.crmpwd
                },
                company: {
                    key: 'companyname',
                    max:96,
                    val: $scope.company
                },
                username: {
                    key: 'username',
                    max:32,
                    val: $scope.username
                },
                phone: {
                    key: 'cellphone',
                    val: $scope.phone
                },
                wechat: {
                    key: 'wechat',
                    val: $scope.wechat
                },
                qq: {
                    key: 'qq',
                    val: $scope.qq
                }
            }
            var reg = /^([a-zA-Z0-9]+[_|\_|\.|\-]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.|\-]?)*[a-zA-Z0-9]+\.[a-zA-Z]{1,63}$/;
            $scope.tip = formJudge(verPar);
            if($scope.email == undefined){
                if ($scope.tip.succ == true) {
                    $scope.tip.succ = false;
                }
                $scope.tip.email = {
                    status:true,
                    txt:"必填"
                }
            }
            if($scope.email != undefined && !reg.test($scope.email)){
                if ($scope.tip.succ == true) {
                    $scope.tip.succ = false;
                }
                $scope.tip.email = {
                    status:true,
                    txt:"请输入正确的邮箱格式"
                }
            }
            if($scope.password != $scope.crmpwd){
                if ($scope.tip.succ == true) {
                    $scope.tip.succ = false;
                }
                $scope.tip.crmpwd = {
                    status:true,
                    txt:"两次密码不一致,请重新输入"
                }
            }
            if ($scope.tip.succ != true) {
                return false;
            }

            $scope.par = par;
            var emailsub = par.email.substring(par.email.indexOf("@")+1,par.email.lastIndexOf("."));
            if($scope.channelNames && ($scope.channelNames.emails.indexOf(angular.lowercase(emailsub)) > -1 || $scope.channelNames.companys.indexOf(angular.lowercase(par.company)) > -1 || $scope.channelNames.companys.indexOf(angular.lowercase(par.name)) > -1)){
                $scope.channelText = true;
            }else{
                $scope.channelText = false;
                $scope.postSave();
            }
        }

        $scope.postSave =function(){
            $scope.channelText = false;
            $scope.errorMessage = "";
            $scope.showLoading();
            $http.post("api/reged/regedaccount",$scope.par).success(function(data){
                $scope.hideLoading();
                if(data.code == -1){
                    $scope.tip.email = {
                        status:true,
                        txt:"该邮箱已注册"
                    }
                    //$scope.errorMessage = "该邮箱已注册";
                }
                else if(data.code == 201){
                    $scope.errorMessage = "注册失败";
                }
                else if(data.code == 250){
                    $scope.errorMessage = "邮件发送失败,请重新注册";
                }else{
129
                    io.register($scope.email);
yangfangfang committed
130

manxiaoqiang committed
131 132 133 134
                    UtilService.setCookie("regId",data.content.id,7);
                    UtilService.setCookie("regEmail",$scope.email,7);
                    UtilService.setCookie("regFlag",0,7);
                    UtilService.setCookie("ryioAcvitation",0,7);
135

manxiaoqiang committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149
                    window.location.href = "activation.html";
                }
            });
        }
        $scope.keyEvt= function(e){
            if(e.keyCode == 13){
                $scope.save();
            }
        }
        $scope.closeWin = function(){
            $scope.channelText = false;
        }
    }
})();