public async Task <IHttpActionResult> Put(int id, [FromBody] MonitorUser user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var result = await db.MonitorUsers.FirstOrDefaultAsync(userID => userID.Id == id);

            if (result == null)
            {
                return(BadRequest("No object found with that ID."));
            }

            if (!(string.IsNullOrEmpty(user.Email)))
            {
                result.Email = user.Email;
            }

            if (!(string.IsNullOrEmpty(user.Country)))
            {
                result.Country = user.Country;
            }

            if (!(string.IsNullOrEmpty(user.Password)))
            {
                result.Password = user.Password;
            }

            db.SaveChanges();

            return(StatusCode(HttpStatusCode.OK));
        }
        private async Task LoadAsync(MonitorUser user)
        {
            var email = await _userManager.GetEmailAsync(user);

            Email = email;

            Input = new InputModel
            {
                NewEmail = email,
            };

            IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);
        }
        public IHttpActionResult Post([FromBody] MonitorUser user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            user.DateCreated = DateTime.Now;

            db.MonitorUsers.Add(user);
            db.SaveChanges();
            return(StatusCode(HttpStatusCode.Created));
        }
Exemple #4
0
        private async Task LoadAsync(MonitorUser user)
        {
            var userName = await _userManager.GetUserNameAsync(user);

            var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

            Username = userName;

            Input = new InputModel
            {
                PhoneNumber = phoneNumber
            };
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new MonitorUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
 public LoginPage()
 {
     //this function implements a remember me function by using a dependency service grabbed from the android/ios platforms
     user = DependencyService.Get <SaveToFile>().ReadFile("");
     //checks whether the file is saved on the device
     isSaveToConfigFile = true;
     InitializeComponent();
     //the remember me will always be enabled for the user to save their credentials on the device and automatically logins in without
     //typing in the login credentials
     if (user != null && user.RememberMe == true)
     {
         unEntry.Text       = user.Name;
         pwdEntry.Text      = user.Password;
         isSaveToConfigFile = false;
         Task.Run(() => this.LoginButton_Clicked(null, null)).Wait();
     }
 }
Exemple #7
0
        private async Task LoadSharedKeyAndQrCodeUriAsync(MonitorUser user)
        {
            // Load the authenticator key & QR code URI to display on the form
            var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);

            if (string.IsNullOrEmpty(unformattedKey))
            {
                await _userManager.ResetAuthenticatorKeyAsync(user);

                unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
            }

            SharedKey = FormatKey(unformattedKey);

            var email = await _userManager.GetEmailAsync(user);

            AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey);
        }
        //function used to read the file that is saved on the device and fetch the saved credentials for login
        public MonitorUser ReadFile(string fileName)
        {   //the path to the storage for the file
            var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            //the name of the folder created on the device
            var directoryname = Path.Combine(documents, "MonitorSystemConfig" + "/" + fileName);
            //the name of the file created on the device
            string fullFilePathName = System.IO.Path.Combine(directoryname.ToString(), "MonitorSystemConfig.dat");

            //try and catch function used to read the information that is stored in the file and as it in JSON format then converted to the proper format
            try
            {
                TextReader reader     = new StreamReader(fullFilePathName);
                string     jsonConfig = reader.ReadLine();
                reader.Close();

                MonitorUser monitorUser = JsonConvert.DeserializeObject <MonitorUser>(jsonConfig);

                return(monitorUser);
            }
            catch
            {
                return(null);;
            }
        }
        //function used to read the file that is saved on the device and fetch the saved credentials for login
        public MonitorUser ReadFile(string fileName)
        { //the path to the storage for the file which is : system\emulated\0 as default
            var documentsPath = Android.OS.Environment.ExternalStorageDirectory.ToString();
            //the name of the folder created on the device
            var dirName = System.IO.Path.Combine(documentsPath.ToString(), "MonitorSystemConfig");
            //the name of the file created on the device
            string fullFilePathName = System.IO.Path.Combine(dirName.ToString(), "MonitorSystemConfig.dat");

            //try and catch function used to read the information that is stored in the file and as it in JSON format then converted to the proper format
            try
            {
                TextReader reader     = new StreamReader(fullFilePathName);
                string     jsonConfig = reader.ReadLine();
                reader.Close();

                MonitorUser monitorUser = JsonConvert.DeserializeObject <MonitorUser>(jsonConfig);

                return(monitorUser);
            }
            catch
            {
                return(null);
            }
        }
        //check whether the user is on the server, if yes then login successful otherwise error and cannot login
        private async Task CheckLogin(string name, string password, MonitorUser monitorUserSaved)
        {
            // Use https to satisfy iOS ATS requirements.
            var client = new HttpClient();
            // var response = await client.GetAsync("http://hp-api.herokuapp.com/api/characters");

            //the url used to call the username and password from the API
            string url = "http://askari.edis.co.nz/api/users?api_username=edis&api_password=edispassword&employee_username="******"&employee_password="******"", responseString);
                }
                //after login the user is taken to the logs page
                await Navigation.PushModalAsync(new LogsPage(name, monitorUserSaved.CheckInterevalInSeconds));
            }
            else if (monitorUser != null)
            {
                monitorUser.RememberMe = rememberBox.IsToggled;
                responseString         = JsonConvert.SerializeObject(monitorUser);

                DependencyService.Get <SaveToFile>().SaveToFile("", responseString);
                await Navigation.PushModalAsync(new LogsPage(name, monitorUser.CheckInterevalInSeconds));
            }
            else
            {
                //DependencyService.Get<INotificationAlarm>().PlayAlarm("alarm.mp3");

                await DisplayAlert("Login", "Login Error", "OK");
            }
        }
Exemple #11
0
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            // Get the information about the user from the external login provider
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ErrorMessage = "Error loading external login information during confirmation.";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            if (ModelState.IsValid)
            {
                var user = new MonitorUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);

                        // If account confirmation is required, we need to show the link if we don't have a real email sender
                        if (_userManager.Options.SignIn.RequireConfirmedAccount)
                        {
                            return(RedirectToPage("./RegisterConfirmation", new { Email = Input.Email }));
                        }

                        await _signInManager.SignInAsync(user, isPersistent : false);

                        var userId = await _userManager.GetUserIdAsync(user);

                        var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                        code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                        var callbackUrl = Url.Page(
                            "/Account/ConfirmEmail",
                            pageHandler: null,
                            values: new { area = "Identity", userId = userId, code = code },
                            protocol: Request.Scheme);

                        await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                          $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            LoginProvider = info.LoginProvider;
            ReturnUrl     = returnUrl;
            return(Page());
        }