コード例 #1
0
ファイル: SignIn.cs プロジェクト: dtopaloglou/ipdevices
        public client Login(string username, string password)
        {
            client c = null;

            try
            {
                using (var context = new ipdevicesEntities())
                {
                    c = context.clients.Where(b => b.Username == username || b.Email == username).DefaultIfEmpty(null).FirstOrDefault();
                    if (c == null)
                    {
                        return(null);
                    }

                    if (Utils.PasswordHelper.BCrypt.CheckPassword(password, c.Password))
                    {
                        Console.WriteLine("Logged in via sign in");
                        return(c);
                    }

                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #2
0
ファイル: Authenticate.cs プロジェクト: dtopaloglou/ipdevices
        public client Login(string username, string password)
        {
            client c = null;

            try
            {
                var clientid = Properties.Settings.Default.clientid;
                using (var context = new ipdevicesEntities())
                {
                    // Are we just authenticating?

                    c = context.clients.Where(b => (b.Username == username || b.Email == username) && b.uid == clientid).DefaultIfEmpty(null).FirstOrDefault();
                    if (c == null)
                    {
                        return(null);
                    }

                    if (Utils.PasswordHelper.BCrypt.CheckPassword(password, c.Password))
                    {
                        Console.WriteLine("Logged in via authentication");
                        return(c);
                    }

                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #3
0
ファイル: ClientLogin.cs プロジェクト: dtopaloglou/ipdevices
 /// <summary>
 /// Checks whether the client actually exist in the database. Used to check prior to ip update.
 /// </summary>
 /// <param name="clientid"></param>
 /// <returns></returns>
 public static bool IsClientAlive(int clientid)
 {
     try
     {
         using (var context = new ipdevicesEntities())
         {
             return(context.clients.Any(c => c.uid == clientid));
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error during client alive check" + ex.Message);
     }
     return(false);
 }
コード例 #4
0
        /// <summary>
        /// Updates IP Address in database. It inserts a new row into the database for the device in question. Done asynchornously no to freeze UI
        /// </summary>
        /// <param name="ip"></param>
        public async void SaveIp(string ip)
        {
            int deviceid = Properties.Settings.Default.deviceId;

            // check if client or device exists
            if (deviceid <= 0)
            {
                return;
            }

            await Task.Run(() =>
            {
                try
                {
                    using (var context = new ipdevicesEntities())
                    {
                        device d = context.devices.Find(deviceid);
                        /// does the device really exist in db?
                        if (d != null)
                        {
                            d.ips.Add(new ip
                            {
                                IP   = ip,
                                Date = DateTime.Now
                            });
                            context.SaveChanges();
                        }
                        else
                        {
                            // if it doesn't, remove device from application registration
                            Console.WriteLine("Device no longer in database. Removed.");
                            Device = null;
                        }


                        _OldAdd = ip; // save ip in settings for later comparisoons
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("An unknown error occurred while updating ip address");
                }
            });
        }
コード例 #5
0
        /// <summary>
        /// Returns true of false if the device name exists for particular client
        /// </summary>
        /// <param name="name">Device name</param>
        /// <param name="clientid">Client id</param>
        /// <returns></returns>
        public static bool DeviceExists(string name, int clientid)
        {
            bool exists = false;

            try
            {
                using (var context = new ipdevicesEntities())
                {
                    if (context.devices.Any(u => u.uid == clientid && u.Name == name))
                    {
                        exists = true;
                    }
                }
            }
            catch (Exception)
            {
                exists = false;
            }

            return(exists);
        }
コード例 #6
0
        /// <summary>
        /// Checks whether the given device name is already taken
        /// </summary>
        /// <param name="name"></param>
        /// <param name="validationErrors"></param>
        /// <returns></returns>
        public bool ValidateDeviceName(string name, out ICollection <string> validationErrors)
        {
            validationErrors = new List <string>();


            // verify that a device name is given
            if (string.IsNullOrWhiteSpace(name))
            {
                validationErrors.Add("Device name is required");
            }

            using (var context = new ipdevicesEntities())
            {
                int clientid = (int)Properties.Settings.Default["clientid"];
                if (DeviceExists(name, clientid))
                {
                    validationErrors.Add("The device name already exists.");
                }
            }

            return(validationErrors.Count == 0);
        }
コード例 #7
0
        private void check()
        {
            var clientid = (int)IPdevices.Properties.Settings.Default["clientid"];
            var deviceid = (int)IPdevices.Properties.Settings.Default["deviceid"];

            if (clientid > 0)
            {
                try
                {
                    SplashScreenHelper.ShowText("Looking for profile...");
                    using (ipdevicesEntities ipde = new ipdevicesEntities())
                    {
                        // does the client actually exist?
                        if (ipde.clients.Any(o => o.uid == clientid))
                        {
                            Console.WriteLine("Client id " + clientid + " was found");

                            SplashScreenHelper.ShowText("Profile found!");
                            var cl = new client();
                            cl = ipde.clients.Find(clientid);

                            SplashScreenHelper.ShowText("Looking for registered device...");

                            // check for registered devices
                            device dev = null;

                            if (cl.devices.Where(d => d.did == deviceid).DefaultIfEmpty(null).FirstOrDefault() != null)
                            {
                                SplashScreenHelper.ShowText("Device found!");
                                dev = ipde.devices.Find(deviceid);
                            }

                            // give client information and device information
                            main = new Main(cl, dev);
                            // apply the proper datacontet to the notify icon
                            notifyIcon             = (TaskbarIcon)FindResource("MyNotifyIcon");
                            notifyIcon.DataContext = new NotifyIconViewModel((MainViewModel)main.DataContext);

                            SplashScreenHelper.Close();

                            main.Show();
                        }
                        else
                        {
                            // well clientid was found in settings, but it doesn't exist in the db. Then just make sure that we reset settings too!
                            Console.WriteLine("Client id " + clientid + " not found in db, resetting settings to default 0");

                            IPdevices.Properties.Settings.Default.clientid = 0;
                            IPdevices.Properties.Settings.Default.deviceId = 0;
                            IPdevices.Properties.Settings.Default.Save();

                            SplashScreenHelper.Close();

                            openLoginWindow();
                        }
                    }
                    ;
                }
                catch (Exception ex)
                {
                    retry();
                    Console.WriteLine("Error logging in: " + ex.Message);
                }
            }
            else
            {
                SplashScreenHelper.Close();
                openLoginWindow();
            }
        }