コード例 #1
0
        public LoginRes GetAccessToken(string userid, string userpw)
        {
            LoginRes result     = new LoginRes();
            User     accessUser = _context.Users.First(p => p.MyId == userid && p.PassWord == userpw);

            if (accessUser == null)
            {
                throw new Exception("401");
            }
            else
            {
                string nick   = accessUser.NickName;
                string base64 = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
                string token  = Base64UrlEncoder.Encode(base64);

                _context.TokenHistories.Add(new TokenHistory()
                {
                    User       = accessUser,
                    AuthToken  = token,
                    CreateTime = DateTime.Now,
                    AccessTime = DateTime.Now
                });

                _context.SaveChanges();
                result.nick        = nick;
                result.accessToken = token;

                return(result);
            }
        }
コード例 #2
0
        internal static int PrepareTestData()
        {
            LoadDBConfig();

            var builder = new DbContextOptionsBuilder <AccountContent>()
                          .UseLoggerFactory(LogSettings.DebugLogger)
                          .UseMySql(AccountControlerTest.ConnectionString);
            var context = new AccountContent(builder.Options);


            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();
            var users = Enumerable.Range(1, 10)
                        .Select(i => new User {
                MyId = "TestID" + i, PassWord = "******" + i, NickName = "Mynick" + i, RegDate = DateTime.Now, IsSocialActive = false
            });

            context.Users.AddRange(users);
            context.SaveChanges();

            var testOpt = new DbContextOptionsBuilder <TestContext>()
                          .UseLoggerFactory(LogSettings.DebugLogger)
                          .UseMySql(AccountControlerTest.TestConnectionString);

            var testContext = new TestContext(testOpt.Options);

            testContext.Database.EnsureDeleted();
            testContext.Database.EnsureCreated();


            return(context.Users.Count(t => t.IsSocialActive == false));
        }