/// <summary> /// 写入登录信息 /// </summary> /// <param name="user">成员信息</param> public virtual void AddCurrent(OperatorEntity user) { try { if (_loginProvider == "Cookie") { CookieHelper.WriteCookie(LoginUserKey, DESEncryptHelper.Encrypt(user.TryToJson()), 60); } else if (_loginProvider == "Session") { SessionHelper.AddSession(LoginUserKey, DESEncryptHelper.Encrypt(user.TryToJson()), 60, 0); } else if (_loginProvider == "Cache") { CacheFactory.GetCacheInstance().WriteCache(DESEncryptHelper.Encrypt(user.TryToJson()), LoginUserKey, user.LoginTime.AddMinutes(60)); } //添加当前登陆用户Token CacheFactory.GetCacheInstance().WriteCache(user.Token, user.UserId, user.LoginTime.AddMinutes(60)); } catch (Exception ex) { throw new Exception(ex.Message); } }
private async void OnLogin_Click(object sender, EventArgs e) { if (verify.CheckInternetConnection() == false) { alertWindow.Alert("", "No internet connection!", Activity); } else { //Preventing from multiple click btnLogin.Enabled = false; try { //Getting id var androidID = Android.Provider.Settings.Secure.GetString(Android.App.Application.Context.ContentResolver, Android.Provider.Settings.Secure.AndroidId); Login login = firebaseHelper.GetLogin(etEmail.Text).ConfigureAwait(false).GetAwaiter().GetResult(); if (encryption.DecodePassword(login.Password) == etPassword.Text) { //Successful login await session.AddSession(androidID, login.Email, login.Token); Android.Support.V4.App.Fragment homeFragment = new HomeFragment(login.Email, login.Token); FragmentManager.BeginTransaction().Replace(Resource.Id.parent_fragment, homeFragment).Commit(); } else { alertWindow.Alert("Error!", "Incorrect email or password!", Activity); btnLogin.Enabled = true; } } catch { alertWindow.Alert("Error!", "Incorrect email or password!", Activity); btnLogin.Enabled = true; } } }
public void Execute() { if (_messageEventArgs.Message.Type.Equals(MessageType.ChatMembersAdded)) { IInstruction chatMembersAddedInstruction = new ChatMembersAddedInstruction(_telegramBotClient, _messageEventArgs, _botPlatform); chatMembersAddedInstruction.Execute(); } if (!_messageEventArgs.Message.Chat.Type.Equals(ChatType.Private)) { return; } SessionHelper.AddSession(new Session() { InstructionId = NextInstruction.None, Name = _messageEventArgs.Message.From.Username, UserId = _messageEventArgs.Message.From.Id, PrivateChatId = _messageEventArgs.Message.Chat.Id }); switch (_messageEventArgs.Message.Text.Trim().Replace("@RssServiceBot", string.Empty)) { case "/start": IInstruction rssEditInstruction = new RssEditInstruction(_telegramBotClient, _messageEventArgs); rssEditInstruction.Execute(); break; case "/bugreport": IInstruction bugReportInstruction = new BugReportInstruction(_telegramBotClient, _messageEventArgs); bugReportInstruction.Execute(); break; default: IInstruction defaultInstruction = new DefaultInstruction(_telegramBotClient, _messageEventArgs, _botPlatform); defaultInstruction.Execute(); break; } }
public ActionResult Create([Bind(Include = "Code,ExamTime,Name,Date,Id")] Exam exam) { if (ModelState.IsValid) { string sessionNew = SessionHelper.CreateSession(exam); var session = db.Sessions.Where(s => s.Name == sessionNew).FirstOrDefault <Session>(); if (session == null) { var createSession = new SessionHelper(); createSession.AddSession(sessionNew); var newSession = db.Sessions.Where(s => s.Name == sessionNew).FirstOrDefault <Session>(); exam.SessionId = newSession.Id; } else { exam.SessionId = session.Id; } db.Exams.Add(exam); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Id = new SelectList(db.Departments, "Id", "Name", exam.Id); return(View(exam)); }
/// <summary> /// 写入登录信息 /// </summary> /// <param name="user">成员信息</param> public virtual void AddCurrent(OperatorEntity user) { try { if (_loginProvider == "Cookie") { #region 解决cookie时,设置数据权限较多时无法登陆的bug CacheFactory.CacheFactory.GetCacheInstance().WriteCache(user.DataAuthorize, LoginUserKey, user.LoginTime.AddHours(12)); user.DataAuthorize = null; #endregion CookieHelper.WriteCookie(LoginUserKey, DESEncryptHelper.Encrypt(user.TryToJson())); } else { SessionHelper.AddSession(LoginUserKey, DESEncryptHelper.Encrypt(user.TryToJson())); } CacheFactory.CacheFactory.GetCacheInstance().WriteCache(user.Token, user.UserId, user.LoginTime.AddHours(12)); } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Execute() { SessionHelper.AddSession(new Session() { InstructionId = NextInstruction.None, Name = _callbackQueryEventArgs.CallbackQuery.From.Username, UserId = _callbackQueryEventArgs.CallbackQuery.From.Id, PrivateChatId = _callbackQueryEventArgs.CallbackQuery.From.Id }); switch (_callbackQueryEventArgs.CallbackQuery.Data) { case "Channels": IInstruction channelsInstruction = new ChannelsInstruction(_telegramBotClient, _callbackQueryEventArgs); channelsInstruction.Execute(); break; case "Groups": IInstruction groupsInstruction = new GroupsInstruction(_telegramBotClient, _callbackQueryEventArgs); groupsInstruction.Execute(); break; case "Rss": IInstruction rssInstruction = new RssInstruction(_telegramBotClient, _callbackQueryEventArgs); rssInstruction.Execute(); break; case "List Groups": IInstruction listGroupsInstruction = new ListGroupsInstruction(_telegramBotClient, _callbackQueryEventArgs, _botPlatform); listGroupsInstruction.Execute(); break; case "List Channels": IInstruction listChannelsInstruction = new ListChannelsInstruction(_telegramBotClient, _callbackQueryEventArgs, _botPlatform); listChannelsInstruction.Execute(); break; case "Add Channel": IInstruction addChannelsInstruction = new AddChannelInstruction(_telegramBotClient, _callbackQueryEventArgs); addChannelsInstruction.Execute(); break; case "List Rss": IInstruction listRssInstruction = new ListRssInstruction(_telegramBotClient, _callbackQueryEventArgs, _botPlatform); listRssInstruction.Execute(); break; case "Add Group": IInstruction addGroupInstruction = new AddGroupInstruction(_telegramBotClient, _callbackQueryEventArgs); addGroupInstruction.Execute(); break; case "Back to Home": IInstruction mainInstruction = new MainInstruction(_telegramBotClient, _callbackQueryEventArgs); mainInstruction.Execute(); break; case "Add Rss": IInstruction addRssInstruction = new AddRssInstruction(_telegramBotClient, _callbackQueryEventArgs); addRssInstruction.Execute(); break; case "Remove Rss": IInstruction removeRssInstruction = new RemoveRssInstruction(_telegramBotClient, _callbackQueryEventArgs, _botPlatform); removeRssInstruction.Execute(); break; case "Remove Channel": IInstruction removeChannelInstruction = new RemoveChannelInstruction(_telegramBotClient, _callbackQueryEventArgs, _botPlatform); removeChannelInstruction.Execute(); break; case "Remove Group": IInstruction removeGroupInstruction = new RemoveGroupInstruction(_telegramBotClient, _callbackQueryEventArgs, _botPlatform); removeGroupInstruction.Execute(); break; } if (_callbackQueryEventArgs.CallbackQuery.Data.StartsWith("Channel_")) { IInstruction channel_Instruction = new Channel_Instruction(_telegramBotClient, _callbackQueryEventArgs, _botPlatform); channel_Instruction.Execute(); } else if (_callbackQueryEventArgs.CallbackQuery.Data.StartsWith("Group_")) { IInstruction group_Instruction = new Group_Instruction(_telegramBotClient, _callbackQueryEventArgs, _botPlatform); group_Instruction.Execute(); } else if (_callbackQueryEventArgs.CallbackQuery.Data.StartsWith("Rss_")) { IInstruction rss_Instruction = new Rss_Instruction(_telegramBotClient, _callbackQueryEventArgs, _botPlatform); rss_Instruction.Execute(); } else if (_callbackQueryEventArgs.CallbackQuery.Data.StartsWith("RemoveRss_")) { IInstruction removeRss_Instruction = new RemoveRss_Instruction(_telegramBotClient, _callbackQueryEventArgs, _botPlatform); removeRss_Instruction.Execute(); } else if (_callbackQueryEventArgs.CallbackQuery.Data.StartsWith("RemoveChannel_")) { IInstruction removeChannel_Instruction = new RemoveChannel_Instruction(_telegramBotClient, _callbackQueryEventArgs, _botPlatform); removeChannel_Instruction.Execute(); } else if (_callbackQueryEventArgs.CallbackQuery.Data.StartsWith("RemoveGroup_")) { IInstruction removeGroup_Instruction = new RemoveGroup_Instruction(_telegramBotClient, _callbackQueryEventArgs, _botPlatform); removeGroup_Instruction.Execute(); } else if (_callbackQueryEventArgs.CallbackQuery.Data.StartsWith("Add_Channel_Rss_")) { IInstruction add_Channel_Rss_Instruction = new Add_Channel_Rss_Instruction(_telegramBotClient, _callbackQueryEventArgs, _botPlatform); add_Channel_Rss_Instruction.Execute(); } else if (_callbackQueryEventArgs.CallbackQuery.Data.StartsWith("Add_Group_Rss_")) { IInstruction add_Group_Rss_Instruction = new Add_Group_Rss_Instruction(_telegramBotClient, _callbackQueryEventArgs, _botPlatform); add_Group_Rss_Instruction.Execute(); } else if (_callbackQueryEventArgs.CallbackQuery.Data.StartsWith("Remove_Rss_")) { IInstruction remove_Rss_Instruction = new Remove_Rss_Instruction(_telegramBotClient, _callbackQueryEventArgs, _botPlatform); remove_Rss_Instruction.Execute(); } }