Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. function dxmpp_form_alter(&$form, $form_state, $form_id) {
  2. if($form_id == 'user_profile_form') {
  3. global $user;
  4. $user_data = db_fetch_object(db_query("SELECT uid, xid, xmpp_username, xmpp_password, password_changed FROM {dxmpp_users} WHERE uid = %d", $user->uid)); //you have to greate a new field to the dxmp_users database names as changed, type int, default 0
  5. //display password edit form if user has an existing dxmpp account
  6. if($user_data->xmpp_username) {
  7. $form['account']['dxmpp_user']['jid'] = array(
  8. '#type' => 'textfield',
  9. '#title' => t('Chat UserID'),
  10. '#value' => $user_data->xmpp_username . '@aktientempel.de',
  11. '#disabled' => TRUE,
  12. '#description' => t('This is your ID you have to use for the Connection to the Chat with an external client.'),
  13. // has to be locked only for informative use!!!!!!!
  14. );
  15. if($user_data->password_changed == '0') {
  16. $form['account']['dxmpp_user']['password'] = array(
  17. '#type' => 'textfield',
  18. '#title' => t('Password'),
  19. '#default_value' => $user_data->xmpp_password,
  20. '#description' => t('This is your default xmpp password for the use with external clients. You can set here your own password. For security reasons please choose a different than your normal login password.'),
  21. );
  22. } else {
  23. $form['account']['dxmpp_user']['password'] = array(
  24. '#type' => 'password',
  25. '#title' => t('Password'),
  26. '#description' => t('You can set here your own password - leave blank if you dont want to change. For security reasons please choose a different than your normal login password.'),
  27. );
  28. }
  29. $form['submit']['#submit'][] = 'dxmpp_form_validate';
  30. return $form;
  31. } else { //if user has no dxmpp user account
  32. $form['account']['dxmpp_user']['jid'] = array(
  33. '#type' => 'textfield',
  34. '#title' => t('JID'),
  35. '#default_value' => t('no ID found!'),
  36. '#description' => t('You do not have an existing chat account. Please visit one of the chats - than your useraccount will be created automaticily.'),
  37. // has to be locked only for informative use!!!!!!!
  38. );
  39. return $form;
  40. }
  41. }
  42. }
  43.  
  44. function dxmpp_form_validate($form, &$form_state) {
  45. if(strlen($form_state['values']['password']) > '0' && strlen($form_state['values']['password']) < '6') {
  46. form_set_error('text', t('Your Password for the using the Chat has not been set. Please enter password of more than 5 character length!'));
  47. } elseif(ereg('[^A-Za-z0-9_!,"()/]', $form_state['values']['password'])) {
  48. form_set_error('text', t('Please use only alphabets a to z, numbers from 0 to 9 or these special characters _!,"()/ in your Chat password'));
  49. } else {
  50. dxmpp_user_login_block_submit($form, &$form_state);
  51. }
  52. }
  53.  
  54. function dxmpp_get_domain($url) {
  55. $nowww = ereg_replace('www\.','',$url);
  56. $domain = parse_url($nowww);
  57. if(!empty($domain["host"])) {
  58. return $domain["host"];
  59. } else {
  60. return $domain["path"];
  61. }
  62. }
  63.  
  64. function dxmpp_user_login_block_submit($form, &$form_state) {
  65. // get the right user data by uid
  66. global $user;
  67. $user_data = db_fetch_object(db_query("SELECT uid, xid, xmpp_username, xmpp_password, password_changed FROM {dxmpp_users} WHERE uid = %d", $user->uid));
  68. //check if password field is set and if it is a new one - if not nothing changed!
  69. if($form_state['values']['password'] != '' && dxmpp_user_decrypt_password($user_data->xmpp_password) != dxmpp_user_decrypt_password($form_state['values']['password'])) {
  70. // just have to figure out the right data from $form_state
  71. $username = $user_data->xmpp_username;
  72. $password = dxmpp_user_encrypt_password($form_state['values']['password']);
  73. $xid = $user_data->xid;
  74. $domain = dxmpp_get_domain($_SERVER['HTTP_HOST']);
  75. //wirte the new data into the dxmpp database
  76. $object = (object) array(
  77. 'xmpp_password' => $password,
  78. 'password_changed' => "1",
  79. 'xid' => $xid,
  80. );
  81. drupal_write_record('dxmpp_users', $object, 'xid');
  82. //use your installation path of ejabebrd!
  83. $password = dxmpp_user_decrypt_password($password);
  84. shell_exec("");
  85. }
  86. user_profile_form_submit($form, &$form_state);
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement