/// <exception cref="WebApiClientException"></exception> private User GetUserImpl(string token, string username) { string apiUrl = Constants.ApiUrlBase + "api/user/{0}/{1}"; HttpWebRequest request = (HttpWebRequest)HttpWebRequest .Create(new Uri(string.Format(apiUrl, token, Encryption.Base64Encode(username)))); request.ContentType = "application/json"; request.Method = "GET"; try { WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); return(JsonConvert.DeserializeObject <User>(new StreamReader(stream).ReadToEnd())); } catch (WebException e) { if (e.Status == WebExceptionStatus.ConnectFailure) { throw new WebApiClientException(WebApiClientError.InternetConnectionError); } return(null); } }
public void Base64() { string encoded = Encryption.Base64Encode(stringData); Assert.AreEqual("Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBtZW4gdG8gY29tZSB0byB0aGUgYWlkIG9mIHRoZWlyIHBhcnR5Lg==", encoded, "Base64 string encode failure"); Assert.AreEqual(stringData, Encryption.Base64DecodeToString(encoded), "Base64 string decode failure"); encoded = Encryption.Base64UrlEncode(stringData); Assert.AreEqual("Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBtZW4gdG8gY29tZSB0byB0aGUgYWlkIG9mIHRoZWlyIHBhcnR5Lg", encoded, "Base64Url encode failure"); Assert.AreEqual(stringData, Encryption.Base64UrlDecodeToString(encoded), "Base64Url decode failure"); }
public async Task RemindPassword(string email) { email = Encryption.Base64Encode(email); var method = new HttpMethod("PATCH"); var request = new HttpRequestMessage(method, "api/ResetPassword/" + email); var response = await _httpClient.SendAsync(request); if (response.StatusCode != HttpStatusCode.OK) { throw new HttpResponseException(response.StatusCode); //NotFound,InternalServerError } }
public async Task <User> GetUserInfo(string token, string email) { email = Encryption.Base64Encode(email); User user; var response = _httpClient.GetAsync("api/user/" + token + "/" + email).Result; if (response.StatusCode == HttpStatusCode.OK) { user = await response.Content.ReadAsAsync <User>(); } else { throw new HttpResponseException(response.StatusCode); //Forbidden,Unauthorized,InternalServerError,BadRequest- niepoprawny email } return(user); }
protected void submitButtonClick(Object sender, EventArgs e) { string username = txtUsername.Text.Trim(); string userID = MyUser.getUserIDFromUsername(username); string email = MyUser.getEmailFromUsername(username); if (Page.IsValid && username != null) { if (Page.IsValid && email != null) { string resetLink = string.Format("{0}Dashboards/ResetPassword.aspx?username={1}&token_email={2}&email={3}&userID={4}", Constants.HOST_URL, Encryption.Base64Encode(username), Encryption.Base64Encode(email), email, Encryption.Base64Encode(userID)); string emailReset = new BL_Configurations().getConfigValue(Constants.resetPasswordEmailText).Rows[0][0].ToString(); Mailer passwordResetMail = new Mailer(Constants.INFO_CHARGENET_EMAIL, Constants.INFO_CHARGENET_PASSWORD, true); passwordResetMail.sendEmail(Constants.INFO_CHARGENET_EMAIL_FROM, email, "Password Reset Request: chargeNET", emailReset.Replace("{0}", username).Replace("{1}", resetLink)); string message = string.Format("{0}{1}. {2}", Messages.aMessageWasSentTo, email, Messages.pleaseCheckYourEmail); Response.Redirect(string.Format("{0}?message={1}&token={2}&username={3}", Constants.LOGIN_URL, message, Encryption.createSHA1(message), Encryption.Base64Encode(username))); } else { lblError.Text = ""; lblError.Text = Messages.usernameNotInDatabase; txtUsername.Text = ""; txtUsername.Focus(); //return; } } else { //Response.Redirect(string.Format("{0}?error={1}&token={2}&token_email={3}&email={4}&username={5}", Constants.RESET_PASSWORD, Classes.Messages.invalidRequest, Encryption.createSHA1(Classes.Messages.invalidRequest), email_enc, email_dec, username_enc)); } }
protected void submitButtonClick(Object sender, EventArgs e) { string username_enc = HttpContext.Current.Request.QueryString["username"]; string userID = Encryption.Base64Decode(HttpContext.Current.Request.QueryString["userID"]); string username_dec = Encryption.Base64Decode(username_enc); string email_dec = Encryption.Base64Decode(HttpContext.Current.Request.QueryString["token_email"]); string email_enc = HttpContext.Current.Request.QueryString["token_email"]; string password = pass.Text; string retypePassword = passConfirm.Text; if (Page.IsValid) { if ((password == retypePassword) && email_dec != null && username_dec != null) { RequestHandler post = new RequestHandler(); post.Url = Constants.RESET_PASSWORD_JSON; post.PostItems.Add("UserName", username_dec); post.PostItems.Add("Password", password); post.PostItems.Add("UserID", userID); post.PostItems.Add("token", Encryption.createSHA1(username_dec + password + userID)); post.Type = RequestHandler.PostTypeEnum.Post; string result = post.Post(); string jsonString = new Regex(@"\{(.*?)\}").Matches(result)[0].ToString(); JSONReturn resetPassword = new JavaScriptSerializer().Deserialize <JSONReturn>(jsonString); if (resetPassword.errorText == null) { Response.Redirect(string.Format("{0}?message={1}&token={2}&username={3}", Constants.LOGIN_URL, Classes.Messages.passwordChangedSuccessfully, Encryption.createSHA1(Classes.Messages.passwordChangedSuccessfully), username_enc)); } else { Response.Redirect(string.Format("{0}?error={1}&token={2}&token_email={3}&email={4}&username={5}&userID={6}", Constants.RESET_PASSWORD, resetPassword.errorText, Encryption.createSHA1(resetPassword.errorText), email_enc, email_dec, username_enc, Encryption.Base64Encode(userID))); } } else { Response.Redirect(string.Format("{0}?error={1}&token={2}&token_email={3}&email={4}&username={5}&userID={6}", Constants.RESET_PASSWORD, Classes.Messages.passwordsDoNotMatch, Encryption.createSHA1(Classes.Messages.passwordsDoNotMatch), email_enc, email_dec, username_enc, Encryption.Base64Encode(userID))); } } else { Response.Redirect(string.Format("{0}?error={1}&token={2}&token_email={3}&email={4}&username={5}&userID={6}", Constants.RESET_PASSWORD, Classes.Messages.invalidRequest, Encryption.createSHA1(Classes.Messages.invalidRequest), email_enc, email_dec, username_enc, Encryption.Base64Encode(userID))); } }
protected void signinClick(object sender, EventArgs e) { if (Page.IsValid) { try { string user_name = userName.Text.Trim(); string pass_word = password.Text.Trim(); LoginResponse login = MyUser.validateUserIS(user_name, pass_word); if (login.credentials == Constants.VALID && login.success == true) { using (DataTable dt = new BL_User().selectByUserName(new Model.ML_User() { username = user_name })) { string type = dt.Rows[0]["role_name"].ToString(); string userID = dt.Rows[0]["id_user"].ToString(); string loginID = login.loginID; SessionHandler.initiateLoginSession(user_name, type, login.token, userID, loginID); switch (type.Trim()) { case Constants.AIGROW_ADMIN: Response.Redirect(Constants.HOME_PATH_DASHBOARDS_ADMIN + "Index.aspx", false); break; case Constants.CHG_NETWORK: Response.Redirect(Constants.HOME_PATH_DASHBOARDS_NETWORK_OWNER + "Index.aspx", false); break; case Constants.AIGROW_CUSTOMER: Response.Redirect(Constants.HOME_PATH_DASHBOARDS_CUSTOMER + "Index.aspx", false); break; case Constants.CHG_OWNER: Response.Redirect(Constants.HOME_PATH_DASHBOARDS_CHARGE_POINT_OWNER + "Index.aspx", false); break; case Constants.CHG_STAFF: Response.Redirect(Constants.HOME_PATH_DASHBOARDS_STAFF + "Index.aspx", false); break; case Constants.CHG_ACCOUNTANT: Response.Redirect(Constants.HOME_PATH_DASHBOARDS_ACCOUNTANT + "Index.aspx", false); break; default: Response.Redirect(string.Format("{0}?error={1}&token={2}", Constants.LOGIN_URL, Messages.undefinedError, Encryption.createSHA1(Messages.undefinedError)), false); break; } } } else { if (login.errorCode == Constants.EC_UserNotActive) { string message = login.errorMessage + " " + Messages.activateYourAccount + " " + Messages.resendActivationEmail.Replace("<here>", "<a href=\"../ResendActivationEmail.aspx?username="******"\">here</a>"); string message_enc = WebUtility.UrlEncode(Encryption.Base64Encode(message)); Response.Redirect(string.Format("{0}?message_enc={1}&token={2}", Constants.LOGIN_URL, message_enc, Encryption.createSHA1(message_enc)), false); } else { Response.Redirect(string.Format("{0}?error={1}&token={2}", Constants.LOGIN_URL, Messages.invalidUsernameOrPassword, Encryption.createSHA1(Messages.invalidUsernameOrPassword)), false); } } } catch (Exception error) { ApplicationUtilities.writeMsg(error.StackTrace); ApplicationUtilities.writeMsg(error.Message); Response.Redirect(string.Format("{0}?error={1}&token={2}", Constants.LOGIN_URL, Messages.undefinedError, Encryption.createSHA1(Messages.undefinedError)), false); } } else { userName.Focus(); } }