public static async Task <DataResponse <string> > Login(LoginSignupModel model) { using (var db = BaseService.CreateSampleContext()) { var response = new DataResponse <string>(); if (string.IsNullOrWhiteSpace(model.Logon) || string.IsNullOrWhiteSpace(model.Password)) { response.ResponseCode = 400; response.Message = "Logon and Password can't be empty"; return(response); } db.TenantID = model.TenantId; var user = await db.GetUserByLogon(model.Logon); if (user == null || !user.VerifyPassword(model.Password)) { response.ResponseCode = 400; response.Message = "User not found or password is incorrect"; return(response); } var sessao = user.CreateSession(); await db.Sessions.AddAsync(sessao); await db.SaveChangesAsync(); response.ResponseCode = 200; response.Data = Convert.ToBase64String(sessao.Token); return(response); } }
public ActionResult DeleteUser(LoginSignupModel LSM) { string webRootPath = _hostingEnvironment.WebRootPath; string contentRootPath = _hostingEnvironment.ContentRootPath; string Filename = (contentRootPath) + "\\App_Data\\Database.json"; dynamic jsondata = String.Empty; using (StreamReader r = new StreamReader(Filename)) { var json = r.ReadToEnd(); r.Close(); List <LoginSignupModel> UserList = JsonConvert.DeserializeObject <List <LoginSignupModel> >(json); dynamic _des = JArray.Parse(json); foreach (var _obj in _des) { if (_obj.Id == LSM.Id) { int IndexNumber = UserList.FindIndex(x => x.Id == LSM.Id); UserList.RemoveAt(IndexNumber); } } jsondata = JsonConvert.SerializeObject(UserList, Formatting.None); System.IO.File.WriteAllText(Filename, jsondata); return(RedirectToAction("Index")); } }
public ActionResult Signup(LoginSignupModel LSM) { try { string webRootPath = _hostingEnvironment.WebRootPath; string contentRootPath = _hostingEnvironment.ContentRootPath; string Filename = (contentRootPath) + "\\App_Data\\Database.json"; dynamic jsondata = String.Empty; using (StreamReader r = new StreamReader(Filename, Encoding.Default)) { dynamic json = r.ReadToEnd(); r.Close(); List <LoginSignupModel> UserList = JsonConvert.DeserializeObject <List <LoginSignupModel> >(json); //LSM.Id=UserList.Count + 1; int IndexNumber = UserList.Max(t => t.Id); // int IndexNumber = UserList.FindLastIndex(x => x.Id ==UserList.FindIndex.[id]); LSM.Id = IndexNumber + 1; UserList.Add(LSM); jsondata = JsonConvert.SerializeObject(UserList, Formatting.None); System.IO.File.WriteAllText(Filename, jsondata); return(RedirectToAction("Index")); } }catch (Exception e) { e.ToString(); } return(View()); }
public static async Task <DataResponse <string> > SignUp(LoginSignupModel model) { using (var db = BaseService.CreateSampleContext()) { var response = new DataResponse <string>(); if (string.IsNullOrWhiteSpace(model.Logon) || string.IsNullOrWhiteSpace(model.Password)) { response.ResponseCode = 400; response.Message = "Logon and Password can't be empty"; return(response); } var grupo = await db.GetTenantById(model.TenantId); if (grupo == null) { response.ResponseCode = 400; response.Message = "Tenant not found."; return(response); } db.TenantID = model.TenantId; var user = await db.GetUserByLogon(model.Logon); if (user != null) { response.ResponseCode = 400; response.Message = "Login Name already in use by another User."; return(response); } user = new DataEntities.User(); user.UserID = Guid.NewGuid(); user.Logon = model.Logon; user.TenantID = model.TenantId; user.RegisterPassword(model.Password); var sessao = user.CreateSession(); await db.Users.AddAsync(user); await db.Sessions.AddAsync(sessao); await db.SaveChangesAsync(); response.ResponseCode = 200; response.Data = Convert.ToBase64String(sessao.Token); return(response); } }
public ActionResult UserDetails(int id) { string webRootPath = _hostingEnvironment.WebRootPath; string contentRootPath = _hostingEnvironment.ContentRootPath; string Filename = (contentRootPath) + "\\App_Data\\Database.json"; using (StreamReader r = new StreamReader(Filename)) { var json = r.ReadToEnd(); r.Close(); List <LoginSignupModel> UserList = JsonConvert.DeserializeObject <List <LoginSignupModel> >(json); LoginSignupModel LSM = new LoginSignupModel(); int IndexNumber = UserList.FindIndex(x => x.Id == id); return(View(UserList[IndexNumber])); } return(View()); }
public IActionResult UserEdit(LoginSignupModel LSM) { string webRootPath = _hostingEnvironment.WebRootPath; string contentRootPath = _hostingEnvironment.ContentRootPath; string Filename = (contentRootPath) + "\\App_Data\\Database.json"; dynamic jsondata = String.Empty; StreamReader r = new StreamReader(Filename); dynamic json = r.ReadToEnd(); r.Close(); List <LoginSignupModel> UserList = JsonConvert.DeserializeObject <List <LoginSignupModel> >(json); dynamic _des = JArray.Parse(json); foreach (var _obj in _des) { if (_obj.Id == LSM.Id) { //UserList.ElementAt(LSM.Id - 1); int IndexNumber = UserList.FindIndex(x => x.Id == LSM.Id); LoginSignupModel UpdateData = new LoginSignupModel(); UpdateData.UserName = LSM.UserName; UpdateData.Id = LSM.Id; UpdateData.Password = LSM.Password; UpdateData.FirstName = LSM.FirstName; UpdateData.SureName = LSM.SureName; UpdateData.MiddleName = LSM.MiddleName; UpdateData.Qualification = LSM.Qualification; UpdateData.Address = LSM.Address; UpdateData.Contact = LSM.Contact; UpdateData.Department = LSM.Department; UpdateData.Email = LSM.Email; UserList[IndexNumber] = UpdateData; } } jsondata = JsonConvert.SerializeObject(UserList, Formatting.None); System.IO.File.WriteAllText(Filename, jsondata); return(RedirectToAction("Index")); //System.IO.File.WriteAllText((contentRootPath) + "\\App_Data\\Database.json", json); return(View()); }
private void Signup() { LoginSignupModel loginSignupModel = new LoginSignupModel { table = tableDynamoDB, username = usernameUser, password = passwordUser }; string jsonBody = JsonUtility.ToJson(loginSignupModel); RestClient.Put(apiUrl, jsonBody).Then(response => { print($"response:: {response.Text}"); }).Catch(error => { print($"error:: {error.Message}"); }); }
public ActionResult AddUser(LoginSignupModel LSM) { return(View()); }
public IActionResult Index(LoginSignupModel LSM) { return(UserEdit(LSM.Id)); }