| 328 fields, |
328 fields, |
| 329 _("OK"), G_CALLBACK(ggp_callback_find_buddies), |
329 _("OK"), G_CALLBACK(ggp_callback_find_buddies), |
| 330 _("Cancel"), NULL, |
330 _("Cancel"), NULL, |
| 331 purple_connection_get_account(gc), NULL, NULL, |
331 purple_connection_get_account(gc), NULL, NULL, |
| 332 gc); |
332 gc); |
| 333 } |
|
| 334 |
|
| 335 /* ----- CHANGE PASSWORD ---------------------------------------------------- */ |
|
| 336 |
|
| 337 typedef struct |
|
| 338 { |
|
| 339 guint inpa; |
|
| 340 struct gg_http *http_req; |
|
| 341 gchar *new_password; |
|
| 342 PurpleAccount *account; |
|
| 343 } ggp_change_passwd_request; |
|
| 344 |
|
| 345 static void ggp_callback_change_passwd_handler(gpointer _req, gint fd, |
|
| 346 PurpleInputCondition cond) |
|
| 347 { |
|
| 348 ggp_change_passwd_request *req = _req; |
|
| 349 const char *messagesTitle = |
|
| 350 _("Change password for the Gadu-Gadu account"); |
|
| 351 |
|
| 352 purple_input_remove(req->inpa); |
|
| 353 |
|
| 354 if (gg_change_passwd_watch_fd(req->http_req) == -1 || |
|
| 355 req->http_req->state == GG_STATE_ERROR) |
|
| 356 goto exit_error; |
|
| 357 |
|
| 358 if (req->http_req->state != GG_STATE_DONE) |
|
| 359 { |
|
| 360 req->inpa = ggp_purplew_http_input_add(req->http_req, |
|
| 361 ggp_callback_change_passwd_handler, req); |
|
| 362 return; |
|
| 363 } |
|
| 364 |
|
| 365 if (req->http_req->data != NULL && |
|
| 366 ((struct gg_pubdir*)req->http_req->data)->success == 1) |
|
| 367 { |
|
| 368 purple_account_set_password(req->account, req->new_password); |
|
| 369 purple_notify_info(req->account, messagesTitle, |
|
| 370 _("Password was changed successfully!"), NULL); |
|
| 371 goto exit_cleanup; |
|
| 372 } |
|
| 373 |
|
| 374 exit_error: |
|
| 375 purple_notify_error(req->account, messagesTitle, |
|
| 376 _("Unable to change password. Error occurred.\n"), NULL); |
|
| 377 |
|
| 378 exit_cleanup: |
|
| 379 gg_change_passwd_free(req->http_req); |
|
| 380 g_free(req->new_password); |
|
| 381 g_free(req); |
|
| 382 } |
|
| 383 |
|
| 384 static void ggp_callback_change_passwd_ok(PurpleConnection *gc, |
|
| 385 PurpleRequestFields *fields) |
|
| 386 { |
|
| 387 PurpleAccount *account; |
|
| 388 GGPInfo *info = purple_connection_get_protocol_data(gc); |
|
| 389 struct gg_http *h; |
|
| 390 gchar *cur, *p1, *p2, *t, *mail; |
|
| 391 const char *messagesTitle = |
|
| 392 _("Change password for the Gadu-Gadu account"); |
|
| 393 |
|
| 394 cur = g_strdup(purple_request_fields_get_string(fields, |
|
| 395 "password_cur")); |
|
| 396 p1 = g_strdup(purple_request_fields_get_string(fields, "password1")); |
|
| 397 p2 = g_strdup(purple_request_fields_get_string(fields, "password2")); |
|
| 398 t = g_strdup(purple_request_fields_get_string(fields, "token")); |
|
| 399 mail = g_strdup(purple_request_fields_get_string(fields, "email")); |
|
| 400 |
|
| 401 account = purple_connection_get_account(gc); |
|
| 402 |
|
| 403 if (cur == NULL || p1 == NULL || p2 == NULL || t == NULL || |
|
| 404 mail == NULL || *cur == '\0' || *p1 == '\0' || *p2 == '\0' || |
|
| 405 *t == '\0' || *mail == '\0') { |
|
| 406 purple_notify_error(account, messagesTitle, |
|
| 407 _("Fill in the fields."), NULL); |
|
| 408 goto exit_err; |
|
| 409 } |
|
| 410 |
|
| 411 if (g_utf8_collate(p1, p2) != 0) { |
|
| 412 purple_notify_error(account, messagesTitle, |
|
| 413 _("New passwords do not match."), NULL); |
|
| 414 goto exit_err; |
|
| 415 } |
|
| 416 |
|
| 417 if (strlen(p1) > 15) { |
|
| 418 purple_notify_error(account, messagesTitle, |
|
| 419 _("New password should be at most 15 characters long."), |
|
| 420 NULL); |
|
| 421 goto exit_err; |
|
| 422 } |
|
| 423 |
|
| 424 if (g_utf8_collate(cur, purple_account_get_password(account)) != 0) { |
|
| 425 purple_notify_error(account, messagesTitle, |
|
| 426 _("Your current password is different from the one that" |
|
| 427 " you specified."), NULL); |
|
| 428 goto exit_err; |
|
| 429 } |
|
| 430 |
|
| 431 if (!purple_email_is_valid(mail)) { |
|
| 432 purple_notify_error(account, messagesTitle, |
|
| 433 _("Invalid email address"), NULL); |
|
| 434 goto exit_err; |
|
| 435 } |
|
| 436 |
|
| 437 purple_debug_info("gg", "Changing password with email \"%s\"...\n", |
|
| 438 mail); |
|
| 439 |
|
| 440 h = gg_change_passwd4( |
|
| 441 ggp_str_to_uin(purple_account_get_username(account)), mail, |
|
| 442 purple_account_get_password(account), p1, info->token->id, t, |
|
| 443 1); |
|
| 444 |
|
| 445 if (h == NULL) |
|
| 446 purple_notify_error(account, messagesTitle, |
|
| 447 _("Unable to change password. Error occurred.\n"), |
|
| 448 NULL); |
|
| 449 else |
|
| 450 { |
|
| 451 ggp_change_passwd_request *req = |
|
| 452 g_new(ggp_change_passwd_request, 1); |
|
| 453 req->http_req = h; |
|
| 454 req->new_password = g_strdup(p1); |
|
| 455 req->account = account; |
|
| 456 |
|
| 457 req->inpa = ggp_purplew_http_input_add(h, |
|
| 458 ggp_callback_change_passwd_handler, req); |
|
| 459 } |
|
| 460 |
|
| 461 exit_err: |
|
| 462 g_free(cur); |
|
| 463 g_free(p1); |
|
| 464 g_free(p2); |
|
| 465 g_free(t); |
|
| 466 g_free(mail); |
|
| 467 } |
|
| 468 |
|
| 469 static void ggp_change_passwd_dialog(PurpleConnection *gc, ggp_account_token *token, gpointer user_data) |
|
| 470 { |
|
| 471 PurpleRequestFields *fields; |
|
| 472 PurpleRequestFieldGroup *group; |
|
| 473 PurpleRequestField *field; |
|
| 474 GGPInfo *info = purple_connection_get_protocol_data(gc); |
|
| 475 char *msg; |
|
| 476 |
|
| 477 if (!token) |
|
| 478 return; |
|
| 479 info->token = token; |
|
| 480 |
|
| 481 fields = purple_request_fields_new(); |
|
| 482 group = purple_request_field_group_new(NULL); |
|
| 483 purple_request_fields_add_group(fields, group); |
|
| 484 |
|
| 485 field = purple_request_field_string_new("password_cur", |
|
| 486 _("Current password"), "", FALSE); |
|
| 487 purple_request_field_string_set_masked(field, TRUE); |
|
| 488 purple_request_field_group_add_field(group, field); |
|
| 489 |
|
| 490 field = purple_request_field_string_new("password1", |
|
| 491 _("Password"), "", FALSE); |
|
| 492 purple_request_field_string_set_masked(field, TRUE); |
|
| 493 purple_request_field_group_add_field(group, field); |
|
| 494 |
|
| 495 field = purple_request_field_string_new("password2", |
|
| 496 _("Password (retype)"), "", FALSE); |
|
| 497 purple_request_field_string_set_masked(field, TRUE); |
|
| 498 purple_request_field_group_add_field(group, field); |
|
| 499 |
|
| 500 field = purple_request_field_string_new("email", |
|
| 501 _("Email Address"), "", FALSE); |
|
| 502 purple_request_field_string_set_masked(field, FALSE); |
|
| 503 purple_request_field_group_add_field(group, field); |
|
| 504 |
|
| 505 field = purple_request_field_string_new("token", |
|
| 506 _("Enter current token"), "", FALSE); |
|
| 507 purple_request_field_string_set_masked(field, FALSE); |
|
| 508 purple_request_field_group_add_field(group, field); |
|
| 509 |
|
| 510 /* original size: 60x24 */ |
|
| 511 field = purple_request_field_image_new("token_img", |
|
| 512 _("Current token"), token->data, token->size); |
|
| 513 purple_request_field_group_add_field(group, field); |
|
| 514 |
|
| 515 msg = g_strdup_printf("%s %s", |
|
| 516 _("Please, enter your current password and your new password " |
|
| 517 "for UIN: "), |
|
| 518 purple_account_get_username(purple_connection_get_account(gc))); |
|
| 519 |
|
| 520 purple_request_fields(gc, |
|
| 521 _("Change Gadu-Gadu Password"), |
|
| 522 _("Change Gadu-Gadu Password"), |
|
| 523 msg, |
|
| 524 fields, _("OK"), G_CALLBACK(ggp_callback_change_passwd_ok), |
|
| 525 _("Cancel"), NULL, |
|
| 526 purple_connection_get_account(gc), NULL, NULL, |
|
| 527 gc); |
|
| 528 |
|
| 529 g_free(msg); |
|
| 530 } |
|
| 531 |
|
| 532 static void ggp_change_passwd(PurplePluginAction *action) |
|
| 533 { |
|
| 534 PurpleConnection *gc = (PurpleConnection *)action->context; |
|
| 535 |
|
| 536 ggp_account_token_request(gc, ggp_change_passwd_dialog, NULL); |
|
| 537 } |
333 } |
| 538 |
334 |
| 539 /* ----- CHANGE STATUS BROADCASTING ------------------------------------------------ */ |
335 /* ----- CHANGE STATUS BROADCASTING ------------------------------------------------ */ |
| 540 |
336 |
| 541 static void ggp_action_change_status_broadcasting_ok(PurpleConnection *gc, PurpleRequestFields *fields) |
337 static void ggp_action_change_status_broadcasting_ok(PurpleConnection *gc, PurpleRequestFields *fields) |