Esempio n. 1
0
        public int Register(string deviceId, string password)
        {
            var dbContext = DbContextFactory.GetContext();
            if (dbContext.Users
                            .Any(p
                                => p.DeviceId == deviceId))
                return 0;

            var newUsr = new User
            {
                PasswordHash = CryptoService.CreatePasswordHash(password),
                DeviceId = deviceId,
                AllowPush = true
            };
            dbContext.Add(newUsr);
            dbContext.SaveChanges();

            return newUsr.Id;
        }
Esempio n. 2
0
        public string CreateSession(User user)
        {
            var dbContext = DbContextFactory.GetContext();

            string sessionKey = CryptoService.CreateSessionKey();

            dbContext.Sessions.Where(s => s.User == user).DeleteAll();

            dbContext.SaveChanges();
            var newSession = new Session
            {
                User = user,
                SessionKey = sessionKey,
                //StarTime = DateTime.Now
            };
            dbContext.Add(newSession);
            dbContext.SaveChanges();

            return sessionKey;
        }
Esempio n. 3
0
 public bool Push(User user, string message)
 {
     var push = PushBrokerFactory.GetBroker();
     if (string.IsNullOrWhiteSpace(user.PushToken)
     || ! user.AllowPush) return false;
     try
     {
         push.QueueNotification(new WindowsPhoneToastNotification()
             .ForEndpointUri(new Uri(user.PushToken))
             .ForOSVersion(WindowsPhoneDeviceOSVersion.MangoSevenPointFive)
             .WithBatchingInterval(BatchingInterval.Immediate)
             .WithNavigatePath("Views/LoginView.xaml")
             .WithText1("Hey there!")
             .WithText2(message));
     }
     catch (Exception)
     {
         return false;
     }
     return true;
 }