settings.js 6.17 KB
Newer Older
1 2 3 4
/**
 * Account Settings function js
 * @since cms:1.4.3.2&1.4.3.3 web:1.0
 **/
5

Masaru Abe committed
6 7
var SETTINGS = {};

8 9
// Init function of page
$(document).ready(function () {
10
    COMMON.showLoading();
11
    //Check if user is logged in
Kang Donghun committed
12
    COMMON.checkAuth(false);
13
    SETTINGS.getToken();
Masaru Abe committed
14
    SETTINGS.initScreen();
15
    $('#dspPwdUpd1').click(SETTINGS.dspPwdUpd1_Click);
16
    COMMON.closeLoading();
17 18
});

19 20 21
/**
 * Get CSRF token from CMS server
 */
22 23 24 25 26 27 28
SETTINGS.getToken = function () {
    var params = {
        sid: ClientData.userInfo_sid(),
    };
    const url = COMMON.format(ClientData.conf_checkApiUrl(), ClientData.userInfo_accountPath()) + CONSTANT.URL.CMS.API.PASSWORD_GET_TOKEN;
    COMMON.cmsAjax(url, params, false, 
    function(data) {
29 30 31
        if (data.token) {
            $('#getToken').val(data.token);
        } else {
32
            COMMON.showAlert("errorGetToken");
33
        }
34 35 36
    }, 
    function(data) {
        if (data.errorMessage) {
37
            COMMON.showAlert(data.errorMessage);
38
        } else {
39
            COMMON.showAlert("errorGetToken");
40 41 42
        }
    });
};
Takumi Imai committed
43 44 45 46
/**
 * Process changing password
 * @param {*} e
 */
47
SETTINGS.dspPwdUpd1_Click = function (e) {
48
    // const tokenVal = $('#tokenVal').val();
49 50
    e.preventDefault();
    var isOK = true;
51
    var msgError = $('#main-error-message');
52
    // Check validation
Masaru Abe committed
53
    if (!ValidationUtil.CheckRequiredForText(SETTINGS.getCurrentPassword())) {
54
        isOK = false;
55 56 57
        msgError.html(COMMON.format(I18N.i18nText('msgEssential'), I18N.i18nText('txtPwdCurr')).toString());
        msgError.show();
    } else {
Masaru Abe committed
58
        if (!ValidationUtil.CheckRequiredForText(SETTINGS.getNewPassword())) {
59
            isOK = false;
60 61
            msgError.html(COMMON.format(I18N.i18nText('msgEssential'), I18N.i18nText('txtPwdNew')).toString());
            msgError.show();
Kang Donghun committed
62 63 64 65 66
        } else if (!ValidationUtil.CheckRequiredForText(SETTINGS.getNewPasswordRe())) {
            isOK = false;
            msgError.html(COMMON.format(I18N.i18nText('msgEssential'), I18N.i18nText('txtPwdNewRe')).toString());
            msgError.show();
        } else {
Masaru Abe committed
67
            if (SETTINGS.getNewPassword() != SETTINGS.getNewPasswordRe()) {
68
                isOK = false;
69
                msgError.html(I18N.i18nText('msgPwdNotMatch'));
Kang Donghun committed
70
                msgError.show();
71 72 73 74
            }
        }
    }
    if (isOK) {
Kang Donghun committed
75 76
        // Check min length
        if (!ValidationUtil.CheckMinLengthForByte(SETTINGS.getNewPassword(), 6)) {
77
            isOK = false;
Kang Donghun committed
78 79
            msgError.html(I18N.i18nText('msgInvaildLength'));
            msgError.show();
80
        }
Kang Donghun committed
81
        // Check max length
Masaru Abe committed
82
        if (!ValidationUtil.CheckMaxLengthForByte(SETTINGS.getNewPassword(), 16)) {
83
            isOK = false;
Kang Donghun committed
84 85
            msgError.html(I18N.i18nText('msgInvaildLength'));
            msgError.show();
86
        }
87
        // Check at least 3 consecutive characters
Kang Donghun committed
88
        if (ValidationUtil.HasSeqChar(SETTINGS.getNewPassword(), 3)) {
89
            isOK = false;
Kang Donghun committed
90 91
            msgError.html(I18N.i18nText('msgHasSeqChar'));
            msgError.show();
Kang Donghun committed
92
        }
93
        // Check 4 same characters in before password
Kang Donghun committed
94
        if (ValidationUtil.ContainSameSeqChar(SETTINGS.getCurrentPassword(), SETTINGS.getNewPassword(), 4)) {
95
            isOK = false;
Kang Donghun committed
96 97
            msgError.html(I18N.i18nText('msgContainSameSeqChar'));
            msgError.show();
Kang Donghun committed
98
        }
99 100 101
    }

    // Do changing password
102
    
103
    if (isOK) {
104
        var getToken = $("#getToken").val();
Kang Donghun committed
105 106 107 108 109 110
        var params = {
            sid: ClientData.userInfo_sid(),
            loginId: ClientData.userInfo_loginId_session(),
            password: SETTINGS.getCurrentPassword(),
            newPassword: SETTINGS.getNewPassword(),
            language: I18N.getCurrentLanguage(),
111
            token: getToken,
112
            appId: 4,
Kang Donghun committed
113
        };
Kang Donghun committed
114
        const url = COMMON.format(ClientData.conf_checkApiUrl(), ClientData.userInfo_accountPath()) + CONSTANT.URL.CMS.API.PASSWORD_CHANGE;
115 116
        COMMON.cmsAjax(url, params, false, SETTINGS.avwCmsApi_passwordChange_success, SETTINGS.avwCmsApi_passwordChange_fail);
    } else {
117 118 119 120
        //alert('error');
    }
};

Takumi Imai committed
121 122 123 124
/**
 * password change success
 * @param {*} data
 */
125
SETTINGS.avwCmsApi_passwordChange_success = function (data) {
126
    // OK
127
    var msgError = $('#main-error-message');
128

Kang Donghun committed
129 130
    if (data.httpStatus != CONSTANT.HTTP_STATUS.OK) {
        msgError.html(I18N.i18nText('msgPwdChangeNG'));
131
        msgError.show();
132
    } else {
Kang Donghun committed
133
        msgError.html('');
134 135 136
        $('#txtPwdCur').val('');
        $('#txtPwdNew').val('');
        $('#txtPwdNewRe').val('');
Kang Donghun committed
137
        /* show messages */
138
        COMMON.showAlert('msgPwdChangeOK',{titleCode: I18N.i18nText('success')});
139 140
    }
};
Takumi Imai committed
141 142 143 144 145 146 147

/**
 * password change fail
 * @param {*} xhr
 * @param {*} b
 * @param {*} c
 */
148
SETTINGS.avwCmsApi_passwordChange_fail = function (xhr, b, c) {
Kang Donghun committed
149 150 151 152 153 154 155 156 157
    /* show error messages */
    var msgError = $('#main-error-message');
    if (xhr.errorMessage && xhr.httpStatus != 0) {
        msgError.html(xhr.errorMessage);
    } else {
        msgError.html(I18N.i18nText('msgPwdChangeNG'));
    }
    msgError.show();
};
158 159 160 161 162 163 164 165

/*
----------------------------------------------------------------------------
Event groups [ end ]
----------------------------------------------------------------------------
*/

// Get input current password
166 167
SETTINGS.getCurrentPassword = function () {
    return $('#txtPwdCur').val();
168 169
};
// Get input new password
170 171
SETTINGS.getNewPassword = function () {
    return $('#txtPwdNew').val();
172
};
173
// Get input new password
174 175
SETTINGS.getNewPasswordRe = function () {
    return $('#txtPwdNewRe').val();
176 177 178
};

// Initalize screen
179
SETTINGS.initScreen = function () {
Kang Donghun committed
180 181
    TEMPLATE.loadHeader('#includedHeader');
    TEMPLATE.loadConfirmModal('#includedConfirmModal');
182 183 184 185 186 187 188 189 190 191
    const navs = [
        {
            titleLang: 'txtTooltipBack',
            href: 'javascript:history.back();',
        },
        {
            titleLang: 'accountSetting',
        },
    ]
    TEMPLATE.loadMainNavsTitle('#includedMainTitle', 'accountSetting', navs, null);
Kang Donghun committed
192
    // Login ID
193
    $('#txtLoginId').text(ClientData.userInfo_loginId_session());
Kang Donghun committed
194
    // Account Path
195
    $('#txtLoginAccPath').text(ClientData.userInfo_accountPath_session());
196

Kang Donghun committed
197
    // Recent login date
198
    $('#txtLastLoginTime').text(ClientData.userInfo_lastLoginTime());
Masaru Abe committed
199
};