Skip to content

Commit c8f6dad

Browse files
committed
Add current user property in WebUntis Client and (will automatically get on login)
1 parent f4c77dd commit c8f6dad

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

WebUntisAPI.Client/Enums.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
namespace WebUntisAPI.Client
88
{
99
/// <summary>
10-
/// Types of a user
10+
/// Types of users
1111
/// </summary>
12-
public enum PersonType
12+
public enum UserType
1313
{
1414
/// <summary>
1515
/// A Untis teacher

WebUntisAPI.Client/WebUntisClient.User.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,29 @@ namespace WebUntisAPI.Client
1414
{
1515
public partial class WebUntisClient
1616
{
17+
/// <summary>
18+
/// The type of the user as that you currently logged in (Student or teacher)
19+
/// </summary>
20+
/// <remarks>
21+
/// <see langword="null"/> when you're not logged in
22+
/// </remarks>
23+
public UserType? UserType => _userType;
24+
private UserType? _userType = null;
25+
26+
/// <summary>
27+
/// The user as that you currently logged in
28+
/// </summary>
29+
/// <remarks>
30+
/// <para>
31+
/// <see langword="null"/> when you're not logged in
32+
/// </para>
33+
/// <para>
34+
/// Don't change any value!
35+
/// </para>
36+
/// </remarks>
37+
public IUser User => _user;
38+
private IUser _user = null;
39+
1740
/// <summary>
1841
/// Get all students on the school
1942
/// </summary>

WebUntisAPI.Client/WebUntisClient.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public WebUntisClient(string clientName, int timeout = 500)
8585
/// <summary>
8686
/// Login as a user in a school to get and write data
8787
/// </summary>
88+
/// <remarks>
89+
/// Information about the user you logged in with is automatically requested
90+
/// </remarks>
8891
/// <param name="school">The school to login (Use only returned instances from <see cref="SchoolSearch.SearchAsync(string, string, CancellationToken)"/>)</param>
8992
/// <param name="username">Name of the user to login</param>
9093
/// <param name="password">Password of the user to login</param>
@@ -100,6 +103,9 @@ public async Task<bool> LoginAsync(School school, string username, string passwo
100103
/// <summary>
101104
/// Login as a user in a school to get and write data
102105
/// </summary>
106+
/// <remarks>
107+
/// Information about the user you logged in with is automatically requested
108+
/// </remarks>
103109
/// <param name="server">server name to login (example: "herakles.webuntis.com")</param>
104110
/// <param name="loginName">School to login (Not the normal school name but the WebUntis internal one)</param>
105111
/// <param name="username">Name of the user to login</param>
@@ -159,12 +165,16 @@ public async Task<bool> LoginAsync(string server, string loginName, string usern
159165
throw responseModel.Error;
160166
}
161167

162-
// Setup data and get default data
168+
// Set data
163169
_serverUrl = serverUrl;
164170
_loginName = loginName;
165171
_sessonId = responseModel.Result.SessionId;
166172
_loggedIn = true;
167173

174+
// Get logged in user data
175+
_userType = (UserType)responseModel.Result.PersonType;
176+
_user = (await GetAllStudentsAsync(ct: ct)).FirstOrDefault(s => s.Id == responseModel.Result.PersonId);
177+
168178
return true;
169179
}
170180

0 commit comments

Comments
 (0)