CPE_learningsite
This repository has no backups
This repository's network speed is throttled to 100KB/sec
Upgrade your account to fix these warnings, or use backups.vc for automated backups
4cd176a439ea516368a5d8827cdf8726027259a6
CPE_learningsite / CPE / CPE.App / CPE.App.Web / Connect / 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 |
using System.Collections.Specialized; using System.Net; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Xml; namespace CPE.App.Web.Connect { public class Login { /// <summary> /// Logs into the Connect service with the information provided and returns the Session object containing the session key. /// </summary> /// <param name="username">The username/login of the account.</param> /// <param name="password">The password for the account.</param> /// <param name="connectURL">The URL to the connect service.</param> /// <param name="accountId">The primary key of the Connect account/host.</param> public static Session UserLogin(string username, string password, string connectURL, int? accountId) { // Attempt login var request = new Request(connectURL, "login"); request.Parameters.Add("login", username); request.Parameters.Add("password", password); if(accountId.HasValue) request.Parameters.Add("account-id", accountId.Value.ToString()); // Check if valid if(request.Execute() && request.Status == Status.OK && !string.IsNullOrEmpty(request.ExtractSessionKey())) { return new Session() { Hostname = connectURL, SessionKey = request.ExtractSessionKey() }; } return null; } /// <summary> /// Resets the password for the specified account. /// </summary> /// <param name="admin">The administrative session.</param> /// <param name="userid">The principal-id of the user's account.</param> /// <param name="password">The new password.</param> public static bool ResetPassword(Session admin, int userid, string password) { var request = new Request(admin, "user-update-pwd"); request.Parameters.Add("user-id", userid.ToString()); request.Parameters.Add("password", password); request.Parameters.Add("password-verify", password); return (request.Execute() && request.Status == Status.OK); } /// <summary> /// Creates a new guest user with the specified information. /// </summary> /// <param name="admin">The administrative session.</param> /// <param name="username">The login/username of the user.</param> /// <param name="password">The password for the user.</param> /// <param name="email">The e-mail for the user.</param> /// <param name="name">The user's full name.</param> /// <returns>Returns the new principal-id of the user.</returns> public static int CreateGuest(Session admin, string username, string password, string email, string firstName, string lastName) { var request = new Request(admin, "principal-update"); request.Parameters.Add("type", "guest"); request.Parameters.Add("has-children", "false"); request.Parameters.Add("login", username); request.Parameters.Add("password", password); request.Parameters.Add("email", email); request.Parameters.Add("first-name", firstName); request.Parameters.Add("last-name", lastName); if(request.Execute() && request.Status == Status.OK) { XmlNode principal = request.XmlResults.SelectSingleNode("/results/principal"); if(principal != null) return int.Parse(principal.Attributes["principal-id"].Value); } return 0; } } } |
Commits for CPE_learningsiteCPE/CPE.App/CPE.App.Web/Connect/Login.cs
Revision | Author | Commited | Message |
---|---|---|---|
4cd176 ... | v.shishlov | Fri 27 Aug, 2021 14:33:17 +0000 | initial commit |