2013-11-03 23:53:49 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2024-01-03 12:57:14 +13:00
|
|
|
|
Copyright (c) 2007-2024 ShareX Team
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
2015-05-27 04:14:09 +12:00
|
|
|
|
using ShareX.HelpersLib;
|
2014-12-11 12:19:28 +13:00
|
|
|
|
using ShareX.UploadersLib.Properties;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System;
|
2013-12-21 05:58:07 +13:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.UploadersLib
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-06-17 00:20:06 +12:00
|
|
|
|
public partial class OAuthControl : UserControl
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
public delegate void OpenButtonClickedEventHandler();
|
|
|
|
|
public event OpenButtonClickedEventHandler OpenButtonClicked;
|
|
|
|
|
|
|
|
|
|
public delegate void CompleteButtonClickedEventHandler(string code);
|
|
|
|
|
public event CompleteButtonClickedEventHandler CompleteButtonClicked;
|
|
|
|
|
|
2014-06-17 01:01:36 +12:00
|
|
|
|
public delegate void ClearButtonclickedEventHandler();
|
|
|
|
|
public event ClearButtonclickedEventHandler ClearButtonClicked;
|
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
public delegate void RefreshButtonClickedEventHandler();
|
|
|
|
|
public event RefreshButtonClickedEventHandler RefreshButtonClicked;
|
|
|
|
|
|
2014-06-17 00:20:06 +12:00
|
|
|
|
private OAuthLoginStatus status;
|
|
|
|
|
|
|
|
|
|
[DefaultValue(OAuthLoginStatus.LoginRequired)]
|
|
|
|
|
public OAuthLoginStatus Status
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-06-17 00:20:06 +12:00
|
|
|
|
return status;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2014-06-17 00:20:06 +12:00
|
|
|
|
status = value;
|
2020-04-17 02:06:25 +12:00
|
|
|
|
UpdateStatusLabel();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2020-04-17 02:06:25 +12:00
|
|
|
|
private OAuthUserInfo userInfo;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2020-04-17 02:06:25 +12:00
|
|
|
|
public OAuthUserInfo UserInfo
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return userInfo;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
userInfo = value;
|
|
|
|
|
UpdateStatusLabel();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-21 05:58:07 +13:00
|
|
|
|
private bool isRefreshable;
|
|
|
|
|
|
|
|
|
|
[DefaultValue(true)]
|
|
|
|
|
public bool IsRefreshable
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return isRefreshable;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
isRefreshable = value;
|
|
|
|
|
|
|
|
|
|
if (isRefreshable)
|
|
|
|
|
{
|
2014-11-11 10:04:21 +13:00
|
|
|
|
gbUserAccount.Size = defaultGroupBoxSize;
|
2013-12-21 05:58:07 +13:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-11-11 10:04:21 +13:00
|
|
|
|
gbUserAccount.Size = smallGroupBoxSize;
|
2013-12-21 05:58:07 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
btnRefreshAuthorization.Visible = isRefreshable;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 10:04:21 +13:00
|
|
|
|
private Size defaultGroupBoxSize, smallGroupBoxSize;
|
|
|
|
|
|
2014-06-17 00:20:06 +12:00
|
|
|
|
public OAuthControl()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2014-06-17 00:20:06 +12:00
|
|
|
|
Status = OAuthLoginStatus.LoginRequired;
|
2014-11-11 10:04:21 +13:00
|
|
|
|
defaultGroupBoxSize = gbUserAccount.Size;
|
|
|
|
|
smallGroupBoxSize = new Size(defaultGroupBoxSize.Width, (int)(defaultGroupBoxSize.Height / 1.16f));
|
2013-12-21 05:58:07 +13:00
|
|
|
|
IsRefreshable = true;
|
2017-06-16 10:57:39 +12:00
|
|
|
|
txtVerificationCode.HandleCreated += (sender, e) => txtVerificationCode.SetWatermark(Resources.OAuthControl_OAuthControl_PasteVerificationCodeHere);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnOpenAuthorizePage_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2021-06-10 10:14:01 +12:00
|
|
|
|
OpenButtonClicked?.Invoke();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtVerificationCode_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
btnCompleteAuthorization.Enabled = !string.IsNullOrEmpty(txtVerificationCode.Text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCompleteAuthorization_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string code = txtVerificationCode.Text;
|
|
|
|
|
|
|
|
|
|
if (CompleteButtonClicked != null && !string.IsNullOrEmpty(code))
|
|
|
|
|
{
|
|
|
|
|
CompleteButtonClicked(code);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnRefreshAuthorization_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2021-06-10 10:14:01 +12:00
|
|
|
|
RefreshButtonClicked?.Invoke();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
2014-06-17 01:01:36 +12:00
|
|
|
|
|
|
|
|
|
private void btnClearAuthorization_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-04-17 02:06:25 +12:00
|
|
|
|
UserInfo = null;
|
|
|
|
|
Status = OAuthLoginStatus.LoginRequired;
|
|
|
|
|
|
2021-06-10 10:14:01 +12:00
|
|
|
|
ClearButtonClicked?.Invoke();
|
2020-04-17 02:06:25 +12:00
|
|
|
|
}
|
2014-06-17 01:01:36 +12:00
|
|
|
|
|
2020-04-17 02:06:25 +12:00
|
|
|
|
private void UpdateStatusLabel()
|
|
|
|
|
{
|
|
|
|
|
switch (Status)
|
|
|
|
|
{
|
|
|
|
|
case OAuthLoginStatus.LoginRequired:
|
|
|
|
|
lblStatusValue.Text = Resources.OAuthControl_Status_NotLoggedIn;
|
|
|
|
|
lblStatusValue.ForeColor = Color.FromArgb(200, 0, 0);
|
|
|
|
|
break;
|
|
|
|
|
case OAuthLoginStatus.LoginSuccessful:
|
|
|
|
|
if (UserInfo != null && !string.IsNullOrEmpty(UserInfo.name))
|
|
|
|
|
{
|
2020-10-22 18:04:05 +13:00
|
|
|
|
lblStatusValue.Text = string.Format(Resources.LoggedInAs0, UserInfo.name);
|
2020-04-17 02:06:25 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lblStatusValue.Text = Resources.OAuthControl_Status_LoggedIn;
|
|
|
|
|
}
|
|
|
|
|
lblStatusValue.ForeColor = Color.FromArgb(0, 160, 0);
|
|
|
|
|
break;
|
|
|
|
|
case OAuthLoginStatus.LoginFailed:
|
|
|
|
|
lblStatusValue.Text = Resources.OAuthControl_Status_LoginFailed;
|
|
|
|
|
lblStatusValue.ForeColor = Color.FromArgb(200, 0, 0);
|
|
|
|
|
break;
|
2014-06-17 01:01:36 +12:00
|
|
|
|
}
|
2020-04-17 02:06:25 +12:00
|
|
|
|
|
|
|
|
|
txtVerificationCode.ResetText();
|
|
|
|
|
btnClearAuthorization.Enabled = btnRefreshAuthorization.Enabled = Status == OAuthLoginStatus.LoginSuccessful;
|
2014-06-17 01:01:36 +12:00
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|