一,登錄界面設計:node
1.將系統編號灰顯,默認初值api
2.密碼欄勾選密碼顯示,這樣就不會明文顯示在頁面上了:數組
Init方法中添加默認值代碼:服務器
METHOD wddoinit . DATA lo_nd_zhis_user TYPE REF TO if_wd_context_node. DATA lo_el_zhis_user TYPE REF TO if_wd_context_element. DATA ls_zhis_user TYPE wd_this->element_zhis_user. DATA lv_sys TYPE wd_this->element_zhis_user-sys. lo_nd_zhis_user = wd_context->get_child_node( name = wd_this->wdctx_zhis_user ). lo_el_zhis_user = lo_nd_zhis_user->get_element( ). *默認登錄系統爲當前服務器系統 IF lo_el_zhis_user IS INITIAL. EXIT. ENDIF. lv_sys = sy-mandt. lo_el_zhis_user->set_attribute( name = `SYS` value = lv_sys ). ENDMETHOD.
2、登錄驗證:函數
1.新建函數組ZLY_PORTALthis
定義全局結構用來存儲用戶數據:spa
2.新建函數ZLY_SET_LOGON將用戶信息存到函數組全局中:設計
3.回到WDA裏 新建MSG方法,視圖中統一顯示消息:code
METHOD msg . * get message manager DATA lo_api_controller TYPE REF TO if_wd_controller. DATA lo_message_manager TYPE REF TO if_wd_message_manager. DATA message TYPE string. lo_api_controller ?= wd_this->wd_get_api( ). lo_message_manager = lo_api_controller->get_message_manager( ). * report message message = lo_message_manager->report_message( message_text = msg message_type = type ). ENDMETHOD.
4.定義登錄按鈕事件,並作相關檢查:blog
METHOD onactionlogon . DATA lo_nd_zhis_user TYPE REF TO if_wd_context_node. DATA lo_el_zhis_user TYPE REF TO if_wd_context_element. DATA ls_zhis_user TYPE wd_this->element_zhis_user. DATA:lv_len TYPE i, lv_hash TYPE md5_fields-hash, gw_user TYPE zlyuser. * navigate from <CONTEXT> to <ZHIS_USER> via lead selection lo_nd_zhis_user = wd_context->get_child_node( name = wd_this->wdctx_zhis_user ). lo_el_zhis_user = lo_nd_zhis_user->get_element( ). IF lo_el_zhis_user IS INITIAL. EXIT. ENDIF. lo_el_zhis_user->get_static_attributes( IMPORTING static_attributes = ls_zhis_user ). IF ls_zhis_user-usern IS NOT INITIAL AND ls_zhis_user-pwd IS NOT INITIAL. lv_len = strlen( ls_zhis_user-pwd ). CALL FUNCTION 'MD5_CALCULATE_HASH_FOR_CHAR' EXPORTING data = ls_zhis_user-pwd length = lv_len version = 1 IMPORTING hash = lv_hash * TABLES * DATA_TAB = EXCEPTIONS no_data = 1 internal_error = 2 OTHERS = 3. IF sy-subrc <> 0. wd_this->msg( EXPORTING type = 3 msg = 'Fcuntion error!'). ELSE. SELECT SINGLE * INTO gw_user FROM zlyuser WHERE userid = ls_zhis_user-usern AND passwd = lv_hash. IF sy-subrc = 0. CALL FUNCTION 'ZLY_SET_LOGON' EXPORTING iw_user = gw_user. ls_zhis_user-usern = gw_user-userid. ls_zhis_user-persnumber = gw_user-partner. ls_zhis_user-augrp = gw_user-user_group. lo_el_zhis_user->set_static_attributes( static_attributes = ls_zhis_user ). wd_this->fire_tomain_plg( ). ELSE. wd_this->msg( EXPORTING type = 3 msg = 'User name OR Password error!'). ENDIF. ENDIF. ELSE. wd_this->msg( EXPORTING type = 3 msg = 'Please fill user and password!'). ENDIF. ENDMETHOD.