4
* GNOME Do is the legal property of its developers, whose names are too numerous
5
* to list here. Please refer to the COPYRIGHT file distributed with this
8
* This program is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
using System.Text.RegularExpressions;
27
namespace GMailContacts
29
public partial class Configuration : Gtk.Bin
31
public Configuration()
34
string username, password;
36
GMail.GetUserAndPassFromKeyring (out username, out password,
38
username_entry.Text = username;
39
passwd_entry.Text = password;
42
protected virtual void OnNewAcctClicked (object sender, System.EventArgs e)
44
Util.Environment.Open ("https://www.google.com/accounts/NewAccount?service=mail");
47
protected virtual void OnApplyBtnClicked (object sender, System.EventArgs e)
49
string username = username_entry.Text.Trim ();
50
string password = passwd_entry.Text.Trim ();
51
apply_btn.Label = "Validating...";
52
apply_btn.Sensitive = false;
53
if (ValidateUsername (username) && ValidatePassword (password)
54
&& GMail.TryConnect (username, password)) {
55
valid_lbl.Markup = "<i>Account validation succeeded</i>!";
56
GMail.WriteAccountToKeyring (username, password, GMail.GAppName);
58
valid_lbl.Markup = "<i>Account validation failed!</i>";
60
apply_btn.Label = "_Apply";
61
apply_btn.Sensitive = true;
64
private bool ValidateUsername (string username)
66
const string emailPattern = @"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\."
67
+ @"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*"
68
+ @"[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?";
70
Regex validEmail = new Regex (emailPattern, RegexOptions.Compiled);
71
return validEmail.IsMatch (username);
74
private bool ValidatePassword (string password)
76
return password.Length >= 8;
b'\\ No newline at end of file'