Passwort Reset Cross Landscape / HTML 5 BSP-Application

Nützliche Abap Codes und Code Fragmente

Passwort Reset Cross Landscape / HTML 5 BSP-Application

Postby Tron » Thu Apr 01, 2021 7:22 am

000.png
Look and Feel
000.png (192.02 KiB) Viewed 2791 times


001.png
001.png (36.55 KiB) Viewed 2790 times


Page Layout of Default.htm
Event OnCreate
Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. * this handler is called once the page is first created (stateful mode)
  2. * it performs a once-off data initialization or object creation
  3.  
  4. * Definition of Dropdown field Option value = SM59 RFC-Connections and Description
  5. *
  6. CLEAR rc .
  7.  
  8. '<option value="NSPCLNT200">NSP Client 200 DEMO Development</option>'
  9. '<option value="NSPCLNT600">NSP Client 600 DEMO Customizing</option>'
  10. INTO systems.
GeSHi ©


Event OnRequest
Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. * the handler is called whenever a request is made for a particular page
  2. * it is used to restore the internal data structures from the request
  3. DATA ireq TYPE REF TO if_http_request.
  4. *DATA h_fields TYPE tihttpnvp.
  5. DATA tf_fields TYPE tihttpnvp.
  6. DATA sf_fields TYPE ihttpnvp.
  7.  
  8. DATA l_email TYPE ad_smtpadr.
  9. DATA l_user TYPE xubname.
  10. DATA l_action TYPE char6. " UNLOCK / NEWPW
  11. DATA l_dest TYPE rfcdest.
  12. DATA t_returnmessages TYPE bapirettab.
  13. DATA s_returnmessages TYPE bapiret2.
  14.  
  15.  
  16. CALL METHOD page->get_request
  17.   RECEIVING
  18.     request = ireq.
  19.  
  20. *CALL METHOD ireq->get_header_fields
  21. *  CHANGING
  22. *    fields = h_fields.
  23.  
  24. DATA l_method TYPE string.
  25.  
  26. CALL METHOD ireq->get_header_field
  27.   EXPORTING
  28.     name  = '~request_method'
  29.   RECEIVING
  30.     value = l_method.
  31.  
  32. IF NOT l_method = 'POST'.
  33.   EXIT.
  34.  
  35. CALL METHOD ireq->get_form_fields
  36.   CHANGING
  37.     fields = tf_fields.
  38.  
  39. CLEAR sf_fields.
  40. READ TABLE tf_fields INTO sf_fields WITH KEY name = 'sapname'.
  41. IF sy-subrc = 0.
  42.   l_user = sf_fields-value.
  43.  
  44. CLEAR sf_fields.
  45. READ TABLE tf_fields INTO sf_fields WITH KEY name = 'emailaddress'.
  46. IF sy-subrc = 0.
  47.   l_email = sf_fields-value.
  48.  
  49. CLEAR sf_fields.
  50. READ TABLE tf_fields INTO sf_fields WITH KEY name = 'action'.
  51. IF sy-subrc = 0.
  52.   l_action = sf_fields-value. " UNLOCK / NEWPW
  53.  
  54. CLEAR sf_fields.
  55. READ TABLE tf_fields INTO sf_fields WITH KEY name = 'sysid'.
  56. IF sy-subrc = 0.
  57.   l_dest = sf_fields-value. " SM59 Destination
  58.  
  59. CALL FUNCTION 'Z_PASSWORD_RESET'
  60.   EXPORTING
  61.     i_email        = l_email
  62.     i_user         = l_user
  63.     i_action       = l_action
  64.     i_system       = l_dest
  65.   IMPORTING
  66.     returnmessages = t_returnmessages
  67.   EXCEPTIONS
  68.     no_user        = 1
  69.     no_email       = 2
  70.     error          = 3
  71.     OTHERS         = 4.
  72.  
  73. IF sy-subrc <> 0.
  74.   rc = 1.
  75.   rc = 2.
  76.  
  77. LOOP AT t_returnmessages INTO s_returnmessages.
  78.   rc_description = s_returnmessages-message.
GeSHi ©


Page Attributes
    EMAIL TYPE AD_SMTPADR E-Mail-Adresse
    RC TYPE SY-SUBRC Rückgabewert, Rückgabewert nach ABAP-Anweisungen
    RC_DESCRIPTION TYPE STRING Result Information
    SAPUSER TYPE XUBNAME Benutzername im Benutzerstamm
    SYSTEMS TYPE STRING Drop Down values

Function Module z_password_reset
Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. FUNCTION z_password_reset.
  2. *"----------------------------------------------------------------------
  3. *"*"Local Interface:
  4. *"  IMPORTING
  5. *"     REFERENCE(I_EMAIL) TYPE  AD_SMTPADR
  6. *"     REFERENCE(I_USER) TYPE  XUBNAME
  7. *"     REFERENCE(I_ACTION) TYPE  CHAR6
  8. *"     REFERENCE(I_SYSTEM) TYPE  RFCDEST DEFAULT 'NONE'
  9. *"  EXPORTING
  10. *"     REFERENCE(RETURNMESSAGES) TYPE  BAPIRETTAB
  11. *"  EXCEPTIONS
  12. *"      NO_USER
  13. *"      NO_EMAIL
  14. *"      ERROR
  15. *"----------------------------------------------------------------------
  16.   DATA l_dummy TYPE string.
  17.   DATA l_email TYPE ad_smtpadr.
  18.   DATA l_email_uc TYPE ad_smtpadr.
  19.   DATA s_locked TYPE bapislockd.
  20.   DATA t_return TYPE TABLE OF bapiret2.
  21.   DATA s_return TYPE bapiret2.
  22.   DATA t_addsmtp TYPE TABLE OF bapiadsmtp.
  23.   DATA s_addsmtp TYPE bapiadsmtp.
  24.   DATA s_logondata TYPE bapilogond.
  25.   DATA msg_text(80) TYPE c. "Message text
  26.   DATA: dest_info TYPE rfcsi.
  27.  
  28. * Check if destination is available
  29.  
  30.   CALL FUNCTION 'RFC_SYSTEM_INFO' DESTINATION i_system
  31.     IMPORTING
  32.       rfcsi_export          = dest_info
  33.     EXCEPTIONS
  34.       communication_failure = 1 MESSAGE msg_text
  35.       system_failure        = 2 MESSAGE msg_text.
  36.  
  37.  
  38. * Check destination is reachable
  39.   IF dest_info IS INITIAL.
  40.     CLEAR s_return.
  41.     s_return-type = 'E'.
  42.     MESSAGE s682(oa) WITH i_system INTO l_dummy.
  43.     s_return-message = l_dummy.
  44.     s_return-id = 'OA'.
  45.     s_return-number = '682'.
  46.     APPEND s_return TO returnmessages.
  47.     RAISE error.
  48.   ENDIF.
  49.  
  50.   CALL FUNCTION 'BAPI_USER_GET_DETAIL' DESTINATION i_system
  51.     EXPORTING
  52.       username              = i_user
  53.     IMPORTING
  54.       logondata             = s_logondata
  55.       islocked              = s_locked
  56.     TABLES
  57.       return                = t_return
  58.       addsmtp               = t_addsmtp
  59.     EXCEPTIONS
  60.       communication_failure = 1 MESSAGE msg_text
  61.       system_failure        = 2 MESSAGE msg_text.
  62.  
  63.   LOOP AT t_return INTO s_return WHERE type = 'E'.
  64.     APPEND s_return TO returnmessages.
  65.     RAISE error.
  66.  
  67. * Check Valid TO Date
  68.   IF NOT s_logondata-gltgb IS INITIAL.
  69.     IF s_logondata-gltgb LT sy-datum.
  70.       CLEAR s_return.
  71.       s_return-type = 'E'.
  72.       MESSAGE s751(01) INTO l_dummy.
  73.       s_return-message = l_dummy.
  74.       s_return-id = '01'.
  75.       s_return-number = '538'.
  76.       APPEND s_return TO returnmessages.
  77.       RAISE error.
  78.     ENDIF.
  79.   ENDIF.
  80.  
  81. * Check Valid FROM Date
  82.   IF NOT s_logondata-gltgv IS INITIAL.
  83.     IF s_logondata-gltgv GT sy-datum.
  84.       CLEAR s_return.
  85.       s_return-type = 'E'.
  86.       MESSAGE s751(01) INTO l_dummy.
  87.       s_return-message = l_dummy.
  88.       s_return-id = '01'.
  89.       s_return-number = '538'.
  90.       APPEND s_return TO returnmessages.
  91.       RAISE error.
  92.     ENDIF.
  93.   ENDIF.
  94.  
  95. * Check Email exsist
  96.   IF t_addsmtp[] IS INITIAL.
  97.     CLEAR s_return.
  98.     s_return-type = 'E'.
  99.     MESSAGE s175(01) INTO l_dummy.
  100.     s_return-message = l_dummy.
  101.     s_return-id = '01'.
  102.     s_return-number = '175'.
  103.     APPEND s_return TO returnmessages.
  104.     RAISE no_email.
  105.   ENDIF.
  106.  
  107.   LOOP AT t_addsmtp INTO s_addsmtp WHERE std_no = 'X'.
  108.     l_email = s_addsmtp-e_mail.
  109.     TRANSLATE l_email TO UPPER CASE.
  110.  
  111. * Check Email against Input
  112.   l_email_uc = i_email.
  113.   TRANSLATE l_email_uc TO UPPER CASE.
  114.   IF NOT l_email = l_email_uc.
  115.     CLEAR s_return.
  116.     s_return-type = 'E'.
  117.     MESSAGE s830(f2) WITH i_email INTO l_dummy.
  118.     s_return-message = l_dummy.
  119.     s_return-id = 'F2'.
  120.     s_return-number = '830'.
  121.     APPEND s_return TO returnmessages.
  122.     RAISE no_email.
  123.   ENDIF.
  124.  
  125.   IF i_action = 'UNLOCK'.
  126.  
  127.     CALL FUNCTION 'BAPI_USER_UNLOCK' DESTINATION i_system
  128.       EXPORTING
  129.         username              = i_user
  130.       TABLES
  131.         return                = t_return
  132.       EXCEPTIONS
  133.         communication_failure = 1 MESSAGE msg_text
  134.         system_failure        = 2 MESSAGE msg_text.
  135.  
  136.     LOOP AT t_return INTO s_return WHERE type ='E'.
  137.       APPEND s_return TO returnmessages.
  138.       RAISE error.
  139.     ENDLOOP.
  140.  
  141.     LOOP AT t_return INTO s_return WHERE type ='S'.
  142.       APPEND s_return TO returnmessages.
  143.       EXIT.
  144.     ENDLOOP.
  145.  
  146. *DE 01  178 Das Kennwort wird nur an die zuvor hinterlegte E-Mail Adresse geschickt
  147.     EXIT.
  148.   ENDIF.
  149.  
  150.   IF i_action = 'NEWPW'.
  151.     DATA l_passwordx TYPE bapipwdx VALUE 'X'.
  152.     DATA l_generate_pwd TYPE  bapiflag-bapiflag VALUE 'X'.
  153.     DATA l_password TYPE bapipwd.
  154.  
  155.     CALL FUNCTION 'BAPI_USER_CHANGE' DESTINATION i_system
  156.       EXPORTING
  157.         username              = i_user
  158. *       PASSWORD              =
  159.         passwordx             = l_passwordx
  160.         generate_pwd          = l_generate_pwd
  161. *       DESCRIPTION           =
  162. *       DESCRIPTIONX          =
  163.       IMPORTING
  164.         generated_password    = l_password
  165.       TABLES
  166.         return                = t_return
  167.       EXCEPTIONS
  168.         communication_failure = 1 MESSAGE msg_text
  169.         system_failure        = 2 MESSAGE msg_text.
  170.  
  171.     LOOP AT t_return INTO s_return WHERE type = 'E'.
  172.       APPEND s_return TO returnmessages.
  173.       RAISE error.
  174.     ENDLOOP.
  175.  
  176.     PERFORM send_email USING i_email l_password.
  177.  
  178.     CLEAR s_return.
  179.     s_return-type = 'E'.
  180.     MESSAGE s178(01) INTO l_dummy.
  181.     s_return-message = l_dummy.
  182.     s_return-id = '01'.
  183.     s_return-number = '178'.
  184.     APPEND s_return TO returnmessages.
  185.     EXIT.
  186.   ENDIF.
  187.  
  188.   CLEAR s_return.
  189.   s_return-type = 'E'.
  190.   l_dummy = 'SHIT'.
  191.   s_return-message = l_dummy.
  192. *    s_return-id = 'F2'.
  193. *    s_return-number = '830'.
  194.   APPEND s_return TO returnmessages.
  195.   RAISE error.
  196.  
  197.  
  198.  
  199. FORM send_email USING i_email TYPE ad_smtpadr i_password TYPE bapipwd.
  200. * For Email contents
  201. *DATA contents_hex TYPE solix_tab.
  202.   DATA lv_internetadr TYPE adr6-smtp_addr.
  203.   DATA lv_subject TYPE so_obj_des.
  204. *DATA lv_attname TYPE sood-objdes.
  205.  
  206.   DATA  send_request       TYPE REF TO cl_bcs.
  207.   DATA  text               TYPE bcsy_text.
  208.   DATA  document           TYPE REF TO cl_document_bcs.
  209.   DATA  recipient          TYPE REF TO if_recipient_bcs.
  210.   DATA  bcs_exception      TYPE REF TO cx_bcs.
  211.   DATA  sent_to_all        TYPE os_boolean.
  212.   DATA l_utask TYPE i.
  213.   DATA l_Date(20).
  214.   DATA l_time(20).
  215.  
  216.   TRY.
  217. *     create the send request
  218.       send_request = cl_bcs=>create_persistent( ).
  219.  
  220. *     create the email body
  221.  
  222.       APPEND 'Your new password' TO text.
  223.       APPEND i_password TO text.
  224.       APPEND '' TO text.
  225.       APPEND 'Have a nice day.' TO text.
  226.       APPEND 'Your SAP-SUPPORT TEAM.' TO text.
  227.  
  228. * Email subject
  229.  
  230.       write sy-datum to l_date.
  231.       CONDENSE l_date NO-GAPS.
  232.       write sy-uzeit to l_time.
  233.       CONDENSE l_time NO-GAPS.
  234.       CONCATENATE 'Your Password reset request from' l_date l_time
  235.       INTO lv_subject SEPARATED BY space.
  236.  
  237.       document = cl_document_bcs=>create_document(
  238.                                 i_type    = 'RAW'
  239.                                 i_text    = text
  240.                                 i_subject = lv_subject ).
  241.  
  242. *=============== Prep Send
  243.  
  244. *     add document to send request
  245.       send_request->set_document( document ).
  246.  
  247. *     create recipient and add to send request
  248.  
  249.       recipient = cl_cam_address_bcs=>create_internet_address( i_email ).
  250.  
  251.       send_request->add_recipient( i_recipient = recipient ).
  252.  
  253.  
  254. *     send
  255.       send_request->set_send_immediately( i_send_immediately = 'X' ).
  256.       sent_to_all = send_request->send( i_with_error_screen = 'X' ).
  257.  
  258. * Im VERBUCHER kein Commit work !!
  259. *Values: 1: in update task, 0: not in update task
  260.       CALL FUNCTION 'TH_IN_UPDATE_TASK'
  261.         IMPORTING
  262.           in_update_task = l_utask.
  263.  
  264.       IF l_utask IS INITIAL.
  265.         COMMIT WORK.
  266.       ENDIF.
  267.  
  268.     CATCH cx_bcs INTO bcs_exception.
  269.       MESSAGE e865(so) WITH bcs_exception->error_type.
  270.   ENDTRY.
  271.  
GeSHi ©
Attachments
Transports.7z
Transport files
(257.27 KiB) Downloaded 80 times
PWRESET.7z
Additional Components
(159.49 KiB) Downloaded 78 times
Tron
.....
.....
 
Posts: 1107
Joined: Sat Aug 04, 2007 10:21 pm

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest

cron