public JsonResult <JsonUserModel> AuthenticateUser([FromBody] UserPresentationModel userPresentationModelObject) { UserBussinessEntity userBussinessEntityObject = MapperFromPresenationtoBL.Mapping <UserPresentationModel, UserBussinessEntity>(userPresentationModelObject); bool isAuthenticated = userBussinessServiceObject.RequestAuthentication(userBussinessEntityObject); if (isAuthenticated) { IAuthContainerModel model = GetJWTContainerModel(userPresentationModelObject.Username, "admin"); IAuthService authService = new JWTService(model.SecretKey); string token = authService.GenerateToken(model); int refreshToken = RandomNumber(0, 256); if (!authService.IsTokenValid(token)) { throw new UnauthorizedAccessException(); } else { ClaimsPrincipal claims = authService.GetTokenClaims(token); refreshTokens[refreshToken] = userPresentationModelObject.Username; } JsonUserModel jsonUserModelObject = new JsonUserModel(); jsonUserModelObject.RefreshToken = userPresentationModelObject.Username; jsonUserModelObject.JWTToken = token; return(Json(jsonUserModelObject)); } return(null); }
public async Task GetFacebookProfile(String token) { var url = "https://graph.facebook.com/v2.7/me/" + "?fields=name" + "&access_token=" + token; var httpClient = new HttpClient(); var userJson = await httpClient.GetStringAsync(url); JsonTextReader reader = new JsonTextReader(new StringReader(userJson)); var result = JsonConvert.DeserializeObject <FaceBookView>(userJson); LoginPage.userName = result.name; App.isLogin = true; App.RootPage.Master.IsVisible = true; App.RootPage.Master.IsEnabled = true; App.RootPage.Detail = new NavigationPage(new HomePage()); List <JsonUserModel> x = await AzureManager.AzureManagerInstance.QueryLogin(result.name); if (x.Count == 0) { JsonUserModel details = new JsonUserModel() { UserName = result.name }; await AzureManager.AzureManagerInstance.AddDetails(details); } else { LoginPage.usermodel = x[0]; ListViewData.populateHashMap(); LoginPage.checkFavs(); } }
public async void writeToDB() { JsonUserModel details = new JsonUserModel() { UserName = SUsername.Text, Email = Email.Text, Password = SPassword.Text }; await AzureManager.AzureManagerInstance.AddDetails(details); SUsername.Text = ""; Email.Text = ""; SPassword.Text = ""; RPassword.Text = ""; }
private async void LoginClicked(Object sender, EventArgs args) { if (Username.Text == null | Password.Text == null) { await DisplayAlert("Invalid Username or Password", "Incorrect username or password", "Ok"); } else { Activity.IsRunning = true; login.IsEnabled = false; signup.IsEnabled = false; List <JsonUserModel> x = await AzureManager.AzureManagerInstance.QueryLogin(Username.Text); if (x.Count == 0) { if (App.isLogin == false) { await DisplayAlert("Invalid Username or Password", "Incorrect username or password", "Ok"); } Activity.IsRunning = false; } else if (!x[0].Password.Equals(Password.Text)) { if (App.isLogin == false) { await DisplayAlert("Invalid Username or Password", "Incorrect username or password", "Ok"); } Activity.IsRunning = false; } else { Activity.IsRunning = false; App.RootPage.Detail = new NavigationPage(new HomePage()); App.isLogin = true; App.RootPage.Master.IsVisible = true; App.RootPage.Master.IsEnabled = true; userName = Username.Text; usermodel = x[0]; ListViewData.populateHashMap(); checkFavs(); } login.IsEnabled = true; signup.IsEnabled = true; } }
public void saveUser(JsonUserModel obj) { var user = new tblUser() { Name = obj.Name, Address = obj.Address }; dbEntities.tblUsers.Add(user); var skillIds = obj.SkillIds.Split(','); foreach (var skill in skillIds) { dbEntities.tblUserSkillLinks.Add(new tblUserSkillLink() { skillId = Convert.ToInt16(skill), userId = user.Id }); } dbEntities.SaveChanges(); }
public AuthModule() : base("/auth") { /* * user's sing in */ Get["/signin/login={login}&password={password}"] = parameters => { var apiKey = AuthenticationHelper.ValidateUser(parameters.login, parameters.password); if (apiKey == null) { return new Response { StatusCode = HttpStatusCode.Unauthorized } } ; JsonUserModel m = new JsonUserModel { Token = apiKey }; String json = JsonConvert.SerializeObject(m); var response = (Response)json; response.ContentType = "application/json"; return(response); }; /* * user's sing out */ Delete["/quit"] = args => { var apiKey = Request.Headers.Authorization; AuthenticationHelper.RemoveApiKey(apiKey); return(new Response { StatusCode = HttpStatusCode.OK }); }; /* * user's sing up */ Get["/signup/login={login}&password={password}"] = parameters => { try { String login = parameters.login; String password = parameters.password; Console.WriteLine(login + password); DatabaseAdapter.createUserEntry(login, password); int userid = DatabaseAdapter.getUserId(login, password); Directory.CreateDirectory("C:\\Users\\g.dzesov\\server\\" + userid); var apiKey = AuthenticationHelper.ValidateUser(login, password); JsonUserModel m = new JsonUserModel { Token = apiKey }; String json = JsonConvert.SerializeObject(m); var response = (Response)json; response.ContentType = "application/json"; return(response); } catch (ArgumentException e) { return(new Response { StatusCode = HttpStatusCode.NotAcceptable, ReasonPhrase = e.Message }); } }; } }
public void Post(JsonUserModel value) { tblusr.saveUser(value); }
public IHttpActionResult LogoutUser([FromBody] JsonUserModel jsonUserModelObject) { jsonUserModelObject.RefreshToken = null; refreshTokens = null; return(Ok("success")); }