This repository has been archived by the owner on May 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Login.cs
146 lines (132 loc) · 4.87 KB
/
Login.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//This is a source code or part of Huggle project
//
//This file contains code for
/// <DOCUMENTATION>
/// This file is processing the initial login request when you are logging into a wiki
/// </DOCUMENTATION>
//Copyright (C) 2011-2012 Huggle team
//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 3 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.
using System;
using System.Collections.Generic;
using System.Text;
namespace huggle3
{
/// <summary>
/// Login request
/// </summary>
public class LoginRequest : RequestCore.Request
{
/// <summary>
/// This is a function which needs to be overriden by request, in case it's not do nothing
/// </summary>
public override void Process()
{
try
{
Core.History("Login-Request.Process()");
Core.WriteLog("Logging in as " + Config.Username);
Login.LoggedIn = false;
LoginResult result;
result = request_api.DoLogin();
//If the login is not a success then try and find out what went wrong and give the relevant error message
Core.WriteLog("Login resulted as " + result.ToString());
if (result != LoginResult.Success)
{
switch (result)
{
case LoginResult.Cancelled:
Login.Error = Languages.Get("login-error-cancelled");
break;
case LoginResult.NotExists:
Login.Error = Languages.Get("login-error-notexists");
break;
case LoginResult.WrongPass:
Login.Error = Languages.Get("login-error-password");
break;
case LoginResult.Throttled:
Login.Error = Languages.Get("login-error-throttled");
break;
case LoginResult.Blocked:
Login.Error = Languages.Get("login-error-blocked");
break;
case LoginResult.NeedToken:
Login.Error = Languages.Get("login-error-needtoken");
break;
case LoginResult.NoName:
Login.Error = Languages.Get("login-error-noname");
break;
case LoginResult.EmptyPass:
Login.Error = Languages.Get("login-error-emptypass");
break;
//There are still some cases this doesnt account for
default: // If it doesnt match any of the above give the default error message
Login.Error = Languages.Get("login-error-unknown");
break;
}
Login.Status = result;
// remove the password from memory for security reasons
Config.Password = "";
Login.LoggingOn = false;
return;
}
Login.phase = Login.LoginState.LoggedIn;
Login.LoggedIn = true;
Complete();
}
catch (Exception B)
{
Core.ExceptionHandler(B);
this.Fail();
}
}
}
/// <summary>
/// Login helper
/// </summary>
static class Login
{
public enum LoginState
{
LoggingIn,
LoadingGlobal,
LoadingLocal,
Whitelist,
LoggedIn,
LoadedLocal,
LoadedGlobal,
Successful,
Error
}
/// <summary>
/// The token.
/// </summary>
public static string Token = null;
/// <summary>
/// The logged in.
/// </summary>
public static bool LoggedIn = false;
/// <summary>
/// The logging on.
/// </summary>
public static bool LoggingOn = false;
/// <summary>
/// The error.
/// </summary>
public static string Error = "";
/// <summary>
/// The phase.
/// </summary>
public static LoginState phase;
/// <summary>
/// The status.
/// </summary>
public static RequestCore.Request.LoginResult Status;
}
}