Skip to content

Commit

Permalink
[PR] [#224] Fix registration and forgot password
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyalehchylin committed Nov 25, 2022
2 parents 9870f02 + b17438d commit f85a32f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 34 deletions.
12 changes: 12 additions & 0 deletions source/EduCATS/Data/DataAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ public async static Task<GroupModel> GetOnlyGroups(int subjectId)
return await GetDataObject(dataAccess, false) as GroupModel;
}

/// <summary>
/// Fetch groups data.
/// </summary>
/// <param name="subjectId">Subject ID.</param>
/// <returns>Group data.</returns>
public async static Task<List<GroupItemModel>> GetGroupsData()
{
var dataAccess = new DataAccess<GroupItemModel>(
"groups_fetch_error", getGroupsDataCallback());
return await GetDataObject(dataAccess, true) as List<GroupItemModel>;
}

public async static Task<LecturesModel> GetLecturesTest(int subjectId, int groupId)
{
var dataAccess = new DataAccess<LecturesModel>(
Expand Down
7 changes: 7 additions & 0 deletions source/EduCATS/Data/DataAccessCallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ public static partial class DataAccess
static async Task<object> getGroupsCallback(
int subjectId) => await AppServices.GetOnlyGroups(subjectId);

/// <summary>
/// Groups data callback.
/// </summary>
/// <param name="subjectId">Subject ID.</param>
/// <returns>Group data.</returns>
static async Task<object> getGroupsDataCallback() => await AppServices.GetGroupsData();

/// <summary>
/// Laboratory works callback.
/// </summary>
Expand Down
5 changes: 0 additions & 5 deletions source/EduCATS/EduCATS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
<Folder Include="Helpers\Date\" />
<Folder Include="Helpers\Date\Extensions\" />
<Folder Include="Helpers\Date\Enums\" />
<Folder Include="Data\Models\Subjects\" />
<Folder Include="Data\Models\News\" />
<Folder Include="Data\Models\Calendar\" />
<Folder Include="Pages\Today\NewsDetails\" />
Expand Down Expand Up @@ -89,7 +88,6 @@
<Folder Include="Pages\Testing\Base\Views\" />
<Folder Include="Pages\Testing\Base\ViewModels\" />
<Folder Include="Pages\Testing\Base\Views\ViewCells\" />
<Folder Include="Data\Models\Testing\" />
<Folder Include="Pages\Testing\Base\Models\" />
<Folder Include="Pages\Testing\Passing\" />
<Folder Include="Pages\Testing\Passing\Models\" />
Expand All @@ -99,7 +97,6 @@
<Folder Include="Data\Models\Testing\Passing\" />
<Folder Include="Networking\Models\Testing\" />
<Folder Include="Pages\Testing\Passing\Views\ViewCells\" />
<Folder Include="Data\Models\Testing\Results\" />
<Folder Include="Pages\Testing\Results\" />
<Folder Include="Pages\Testing\Results\Views\" />
<Folder Include="Pages\Testing\Results\ViewModels\" />
Expand All @@ -108,12 +105,10 @@
<Folder Include="Pages\Eemc\Views\" />
<Folder Include="Pages\Eemc\ViewModels\" />
<Folder Include="Networking\Models\Eemc\" />
<Folder Include="Data\Models\Eemc\" />
<Folder Include="Pages\Eemc\Views\ViewCell\" />
<Folder Include="Pages\Files\" />
<Folder Include="Pages\Files\Views\" />
<Folder Include="Pages\Files\ViewModels\" />
<Folder Include="Data\Models\Files\" />
<Folder Include="Pages\Files\Models\" />
<Folder Include="Pages\Files\Views\ViewCells\" />
<Folder Include="Data\Models\Recommendations\" />
Expand Down
10 changes: 10 additions & 0 deletions source/EduCATS/Networking/AppServices/AppServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ public static async Task<object> GetOnlyGroups(int subjectId)
return await AppServicesController.Request($"{Links.GetOnlyGroups}/{subjectId}");
}

/// <summary>
/// Fetch groups data.
/// </summary>
/// <param name="subjectId">Subject ID.</param>
/// <returns>Group data.</returns>
public static async Task<object> GetGroupsData()
{
return await AppServicesController.Request($"{Links.GetGroupsData}");
}

/// <summary>
/// Fetch laboratory works data request.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions source/EduCATS/Networking/Links.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public static class Links
/// </summary>
public static string GetOnlyGroups => $"{Servers.Current}/Services/CoreService.svc/GetOnlyGroups";

/// <summary>
/// Get groups data URL.
/// </summary>
public static string GetGroupsData => $"{Servers.Current}/Administration/GetGroupsJson";

/// <summary>
/// Get laboratory works URL.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public bool LatinPassword()
{
for (int i = 0; i < NewPassword.Length; i++)
{
if (!(((NewPassword[i] >= 'a') && (NewPassword[i] <= 'z')) || ((NewPassword[i] >= 'A') && (NewPassword[i] <= 'Z')) ||
(int.Parse(NewPassword[i].ToString()) >= 0) && (int.Parse(NewPassword[i].ToString()) <= 9)))
if (!(((NewPassword[i] >= 'a') && (NewPassword[i] <= 'z')) || ((NewPassword[i] >= 'A') && (NewPassword[i] <= 'Z')) || (NewPassword[i] == '_') ||
((NewPassword[i] >= '0') && NewPassword[i] <= '9')))
{
latin_password = false;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public bool checkCredentials()
string.IsNullOrEmpty(ConfirmPassword) ||
string.IsNullOrEmpty(Name) ||
string.IsNullOrEmpty(Surname) ||
ReferenceEquals(Group.Id, null) ||
ReferenceEquals(SelectedQuestionId, null) ||
ReferenceEquals(Group, null) ||
ReferenceEquals(SelectedQuestionId, 0) ||
string.IsNullOrEmpty(AnswerToSecretQuestion))
{
return false;
Expand All @@ -72,8 +72,8 @@ public bool LatinPassword()

for (int i = 0; i < Password.Length; i++)
{
if (!(((Password[i] >= 'a') && (Password[i] <= 'z')) || ((Password[i] >= 'A') && (Password[i] <= 'Z')) ||
(int.Parse(Password[i].ToString()) >= 0) && (int.Parse(Password[i].ToString()) <= 9)))
if (!(((Password[i] >= 'a') && (Password[i] <= 'z')) || ((Password[i] >= 'A') && (Password[i] <= 'Z')) || (Password[i] == '_') ||
((Password[i] >= '0') && Password[i] <= '9')))
{
latin_password = false;
break;
Expand All @@ -98,7 +98,7 @@ public bool CheckNameOfUser(string nameOfUser)
((nameOfUser[i] >= 'a') && (nameOfUser[i] <= 'z')) || ((nameOfUser[i] >= 'A') && (nameOfUser[i] <= 'Z')) ||
((nameOfUser[i] >= 'а') && (nameOfUser[i] <= 'я')) || ((nameOfUser[i] >= 'А') && (nameOfUser[i] <= 'Я')) ||
((nameOfUser[i] == '_') || (nameOfUser[i] == ' ') || (nameOfUser[i] == '-')) ||
((int.Parse(nameOfUser[i].ToString()) >= 0 && int.Parse(nameOfUser[i].ToString()) <= 9))))
(nameOfUser[i] >= '0' && nameOfUser[i] <= '9')))
{
name = false;
break;
Expand All @@ -120,7 +120,7 @@ public bool LatinUserName()
for (int i = 0; i < UserName.Length; i++)
{
if (!(((UserName[i] >= 'a') && (UserName[i] <= 'z')) || ((UserName[i] >= 'A') && (UserName[i] <= 'Z'))
|| ((int.Parse(UserName[i].ToString()) >= 0) && (int.Parse(UserName[i].ToString()) <= 9))
|| ((UserName[i] >= '0') && (UserName[i] <= '9'))
|| (UserName[i] == '_')
|| (UserName[i] == '.')
|| (UserName[i] == '-')
Expand All @@ -147,14 +147,16 @@ public async Task<Task<object>> startRegister()
bool correctPatronymic = true;
bool correctName = CheckNameOfUser(Name);
bool correctSurname = CheckNameOfUser(Surname);
bool secretAnswer = CheckNameOfUser(AnswerToSecretQuestion);
if (Patronymic != null)
{
correctPatronymic = CheckNameOfUser(Patronymic);
}
SelectedQuestionId = 0;
int uppercase = UpperCaseLettersInPassword();
bool latin_password = LatinPassword();
bool latin_username = LatinUserName();
bool latinPassword = LatinPassword();
bool latinUsername = LatinUserName();

if (QuestionId == CrossLocalization.Translate("mother_last_name"))
{
SelectedQuestionId = 1;
Expand All @@ -171,7 +173,7 @@ public async Task<Task<object>> startRegister()
var userExists = await VerifyUserNameAsync(UserName);
if (JsonConvert.DeserializeObject<string>(userExists.Key) == "true")
{
_services.Dialogs.ShowError(CrossLocalization.Translate(""));
_services.Dialogs.ShowError(CrossLocalization.Translate("user_exists"));
return Task.FromResult<object>(null);
}

Expand All @@ -182,7 +184,7 @@ public async Task<Task<object>> startRegister()
return Task.FromResult<object>(null);
}

if (!(latin_username == true))
if (!(latinUsername == true))
{
_services.Dialogs.ShowMessage(CrossLocalization.Translate("username_error"),
CrossLocalization.Translate("latin_letters"));
Expand All @@ -195,7 +197,7 @@ public async Task<Task<object>> startRegister()
return Task.FromResult<object>(null);
}

if (!(uppercase != 0 && latin_password == true))
if (!(uppercase != 0 && latinPassword == true))
{
_services.Dialogs.ShowMessage(CrossLocalization.Translate("password_not_correct"),
CrossLocalization.Translate("latin_password"));
Expand Down
25 changes: 9 additions & 16 deletions source/EduCATS/Pages/Registration/Views/RegistrationPageView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EduCATS.Data.Models;
using EduCATS.Data;
using EduCATS.Data.Models;
using EduCATS.Helpers.Forms;
using EduCATS.Helpers.Forms.Styles;
using EduCATS.Pages.Registration.ViewModels;
Expand Down Expand Up @@ -37,23 +38,15 @@ public RegistrationPageView()
BindingContext = new RegistrationPageViewModel(new PlatformServices());
NavigationPage.SetHasNavigationBar(this, false);
BackgroundColor = Color.FromHex(Theme.Current.AppBackgroundColor);
WebRequest request = WebRequest.Create("http://educats.by/Administration/GetGroupsJson");
WebResponse response = request.GetResponse();
string json = "";
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
string line = "";
while ((line = reader.ReadLine()) != null)
{
json += line;
}
}
};
groupData = JsonConvert.DeserializeObject<List<GroupItemModel>>(json);
setGroupData();
}

async void setGroupData()
{
groupData = await DataAccess.GetGroupsData();
createView();
}

void createView()
{
var backgroundImage = createBackgroundImage();
Expand Down

0 comments on commit f85a32f

Please sign in to comment.