public IActionResult Auth([FromBody] OauthViewModel viewModel) { var response = ResponseModelFactory.CreateInstance; var user = _sysUserRepo.FindEntity(x => x.LoginName == viewModel.UserName && x.Password == viewModel.Password ); if (user == null) { response.SetNotFound("用户名密码不正确"); return(Ok(response)); } var claimsIdentity = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, viewModel.UserName), new Claim("id", user.Id.ToString()), new Claim("avatar", ""), new Claim("LoginName", user.LoginName), new Claim("displayName", user.DisplayName), new Claim("userType", ((int)user.UserType).ToString()) }); var token = JwtBearerAuthenticationExtension.GetJwtAccessToken(_appSettings, claimsIdentity); Log(user.Id, user.LoginName + "_" + user.DisplayName); var result = new { token, user.DisplayName }; response.SetData(result); return(Ok(response)); }
public IActionResult Index() { if (myHub.hubConfig == null || String.IsNullOrEmpty(j64Config.ChannelDevice) || String.IsNullOrEmpty(j64Config.VolumeDevice)) { return(RedirectToAction("Edit", "FirstTimeConfig")); } var oauth = OauthRepository.Get(); var ovm = new OauthViewModel() { ClientKey = oauth.clientKey, SecretKey = oauth.secretKey }; return(View(ovm)); }
public async Task <IActionResult> CreateSmartApp(OauthViewModel authInfo) { if (ModelState.IsValid == false) { return(View(authInfo)); } var conn = new SmartThingsConnection(); if (await conn.Login(authInfo.STUserId, authInfo.STPassword) == false) { ModelState.AddModelError("STPassword", "Could not connect to smart things using the supplied credentials"); return(View("Index", authInfo)); } var cs = new DeviceTypeRepository(conn, "j64 Channel Switch", $"{myEnv.WebRootPath}/../SmartThingApps/j64ChannelSwitchDevice.groovy"); var ss = new DeviceTypeRepository(conn, "j64 Surfing Switch", $"{myEnv.WebRootPath}/../SmartThingApps/j64SurfingSwitchDevice.groovy"); var vs = new DeviceTypeRepository(conn, "j64 VCR Switch", $"{myEnv.WebRootPath}/../SmartThingApps/j64VcrSwitchDevice.groovy"); var os = new DeviceTypeRepository(conn, "j64 Volume Switch", $"{myEnv.WebRootPath}/../SmartThingApps/j64VolumeSwitchDevice.groovy"); var cc = new DeviceTypeRepository(conn, "j64 Custom Command Switch", $"{myEnv.WebRootPath}/../SmartThingApps/j64CustomCommandSwitchDevice.groovy"); var har = new SmartAppRepository(conn, "j64 Harmony", $"{myEnv.WebRootPath}/../SmartThingApps/j64HarmonySmartApp.groovy"); // Save the client/secret keys var oauth = OauthRepository.Get(); oauth.clientKey = har.clientKey; oauth.secretKey = har.secretKey; OauthRepository.Save(oauth); var ovm = new OauthViewModel() { ClientKey = oauth.clientKey, SecretKey = oauth.secretKey }; return(View("Index", ovm)); }