private void RegistrationCompleted(object sender, UploadStringCompletedEventArgs e) { Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "YapperServiceProxy::RegisterNewUser ", "end")); UserCookieModel userCookie = null; if (e.Error == null) { DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(UserCookieModel)); userCookie = (UserCookieModel)jsonSerializer.ReadObject(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(e.Result))); } else { Deployment.Current.Dispatcher.BeginInvoke(() => { if (UserSettingsModel.Instance.DebugEnabled == true) { MessageBox.Show(e.Error.Message); } }); } Action <UserCookieModel> callback = e.UserState as Action <UserCookieModel>; callback(userCookie); }
private void ValidationComplete(UserCookieModel cookie) { if (cookie != null) { UserSettingsModel.Instance.Cookie = cookie.AuthCookie; byte[] publicKey = null, privateKey = null; if (publicKey == null) { RsaEncryption.GenerateKeys(out publicKey, out privateKey); } UserSettingsModel.Instance.PrivateKey = privateKey; cookie.User.PublicKey = publicKey; UserSettingsModel.Instance.Save(cookie.User); YapperServiceProxy.Instance.UpdateUserPublicKey( cookie.User, delegate(bool success) { if (!success) { // clear the private key if public key update fails UserSettingsModel.Instance.PrivateKey = null; } } ); } Messenger.Default.Send <VerificationCodeValidationCompleteEvent>(new VerificationCodeValidationCompleteEvent(cookie != null)); this.IsValidating = false; }
private UserCookieModel CreateCookieModel(string userId, bool isConfigPage = true) { var widgets = isConfigPage ? base.Function.GetChildren() .Where(f => (f.Visible & VisibleType.Widget) == VisibleType.Widget) .OrderBy(f => f.Ord) .ThenBy(f => f.Id) .ToArray() : AppManager.Instance.GetWidgetFunctions(); var widgetModel = widgets.Select(w => new WidgetModel { WidgetId = w.Id, WidgetTitle = w.Name, Order = w.Ord.ToString(), WidgetBody = "", WidgetColumn = WidgetPlace.Left, WidgetHeight = "250", WidgetShowCloseButton = "false", RenderUrl = w.Location, RenderAction = w.ActionName, RenderController = w.ControllerName }).ToList(); var cookieModel = new UserCookieModel { UserId = userId, //UserName = "******", PanelHeight = "100", PanelWidth = "100", PanelIncision = "['50%','50%']", Widgets = widgetModel }; return(cookieModel); }
/// <summary> /// User Cookie解密 /// </summary> /// <param name="cookieValue"></param> /// <param name="key">DES加密key</param> /// <returns></returns> public static UserCookieModel DescryptUserCookie(string cookieValue, string key) { UserCookieModel u = new UserCookieModel(); if (string.IsNullOrEmpty(cookieValue)) { return(u); } string s = DesUtil.Decrypt3DES_2(cookieValue, key); string[] ss = s.Split('\f'); u._id = int.Parse(ss[0]); u._uname = ss[1]; u._ip = ss[2]; u._timestamp = long.Parse(ss[3]); return(u); }
private void SyncUserCookieWidgetData(ref UserCookieModel userCookieModel) { var widgets = AppManager.Instance.GetWidgetFunctions(); for (int i = userCookieModel.Widgets.Count - 1; i >= 0; i--) { var userWidget = userCookieModel.Widgets[i]; var widgetItem = widgets.Where(w => w.Id == userWidget.WidgetId).FirstOrDefault(); if (widgetItem != null) { userWidget.WidgetTitle = widgetItem.Name; userWidget.RenderUrl = widgetItem.Location; userWidget.RenderAction = widgetItem.ActionName; userWidget.RenderController = widgetItem.ControllerName; } else { userCookieModel.Widgets.Remove(userWidget); } } }
private void RegistrationCompleted(UserCookieModel userCookie) { if (userCookie != null && userCookie.User != null) { byte[] publicKey = null, privateKey = null; if (publicKey == null) { RsaEncryption.GenerateKeys(out publicKey, out privateKey); } UserSettingsModel.Instance.PrivateKey = privateKey; userCookie.User.PublicKey = publicKey; UserSettingsModel.Instance.Save(userCookie.User); UserSettingsModel.Instance.Cookie = userCookie.AuthCookie; YapperServiceProxy.Instance.UpdateUserPublicKey( userCookie.User, delegate(bool success) { if (!success) { // clear the private key if public key update fails UserSettingsModel.Instance.PrivateKey = null; } } ); } else { this.IsRegistering = false; } Messenger.Default.Send <RegistrationCompleteEvent>(new RegistrationCompleteEvent() { User = userCookie == null ? null : userCookie.User }); }
private void ValidationCompleted(object sender, DownloadStringCompletedEventArgs e) { UserCookieModel cookie = null; if (e.Error == null) { DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(UserCookieModel)); cookie = (UserCookieModel)jsonSerializer.ReadObject(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(e.Result))); } else { Deployment.Current.Dispatcher.BeginInvoke(() => { if (UserSettingsModel.Instance.DebugEnabled == true) { MessageBox.Show(e.Error.Message); } }); } Action <UserCookieModel> callback = e.UserState as Action <UserCookieModel>; callback(cookie); }
/// <summary> /// User Cookie 加密 /// </summary> /// <param name="cookieModel">用户Cookie实体</param> /// <param name="key">DES加密key</param> /// <returns></returns> public static string EncryptUserCookie(UserCookieModel cookieModel, string key) { return(DesUtil.Encrypt3DES_2(string.Concat(cookieModel._id, "\f", cookieModel._uname, "\f", cookieModel._ip, "\f", cookieModel._timestamp), key)); }
private List <string> GetChkWidgetIds(UserCookieModel cookieModel) { var list = cookieModel.Widgets.Select(w => w.WidgetId).ToList(); return(list); }