public ActionResult loginFB(VmLogin vmLogin) { Cliente cliente = context.Cliente.FirstOrDefault(x => x.IDApi == vmLogin.FbID); if (cliente == null) { cliente = new Cliente(); cliente.Usuario = vmLogin.usuario; cliente.Clave = ""; cliente.Correo = vmLogin.correo; cliente.IDApi = vmLogin.FbID; cliente.Foto = vmLogin.imagen; //string imageFile = System.Web.HttpContext.Current.Server.MapPath("~/Content/images/user.png"); //var srcImage = Image.FromFile(imageFile); //var stream = new MemoryStream(); //srcImage.Save(stream, ImageFormat.Png); //cliente.Foto= stream.ToArray(); cliente.Rol = "User"; GYMEntities context = new GYMEntities(); context.Cliente.Add(cliente); context.SaveChanges(); Session["objUsuario"] = cliente; Session["rol"] = "C"; return(RedirectToAction("gimnacioMapa")); } Session["objUsuario"] = cliente; Session["rol"] = "C"; return(RedirectToAction("gimnacioMapa")); //return View(); }
public Metadata Login(VmLogin model) { try { var user = this._service.Login(model); var identity = new ClaimsIdentity(OAuthDefaults.AuthenticationType); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id.ToString())); identity.AddClaim(new Claim(ClaimTypes.Name, user.Name)); var currentUtc = DateTime.UtcNow; AuthenticationTicket ticket = new AuthenticationTicket(identity, new AuthenticationProperties { IssuedUtc = currentUtc, ExpiresUtc = currentUtc.AddDays(1) }); var token = Startup.OAuthOptions.AccessTokenFormat.Protect(ticket); return(new Metadata(token)); } catch (LocalizedException ex) { return(new Metadata(string.Empty) { Success = false, Message = ex.Message }); } catch (Exception) { throw; } }
public VmAccount Login(VmLogin model) { if (string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password)) { return new VmAccount { Name = "Tourist", Login = "******", Id = -1 } } ; ValidationProvider.Validate(model); var repository = UnitOfWork.Repository <Account>(); var entity = repository.Queryable().Include(m => m.Player).Where(m => m.Login == model.Login).FirstOrDefault(); if (entity == null) { throw new DataNotFoundException("User"); } if (entity.Password != ("GG" + model.Password + model.Login).Md5Encrypt()) { throw new LocalizedException("IncorrectPassword"); } return(new VmAccount { Name = entity.Player.Name, Login = entity.Login, Id = entity.Id }); }
public ActionResult Login(VmLogin login) { if (ModelState.IsValid) { AdmiNLogin admin = db.AdmiNLogins.FirstOrDefault(a => a.Username == login.Username); if (admin != null) { if (admin.Password == login.Password) { Session["Admin"] = admin; Session["AdminId"] = admin.Id; return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("Password", "Wronge"); } } else { ModelState.AddModelError("Username", "Wronge"); } } return(View()); }
public async Task <CookieCollection> LoginTzbAsync(VmLogin para) { var cookieJar = new CookieContainer(); using (var handler = new HttpClientHandler { CookieContainer = cookieJar, UseCookies = true, }) { using (var client = CreateHttpClient(AppSetting.Instance.HostTzb, handler)) { var formData = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("logonUsername", para.UserName), new KeyValuePair <string, string>("password", para.Password.Md5Encrypt()), new KeyValuePair <string, string>("rememberType", "10080"), new KeyValuePair <string, string>("loginType", "user"), new KeyValuePair <string, string>("verificationCode", string.Empty), new KeyValuePair <string, string>("timeStamp", TimeExtension.GetTimeStamp().ToString()), }); var Uri = CreateUri("/auth/loginSubmit", AppSetting.Instance.HostTzb, HttpSchema.HTTPS); var response = await client.PostAsync(Uri, formData); if (response.IsSuccessStatusCode) { var responseCookies = cookieJar.GetCookies(Uri); return(responseCookies); } } } return(new CookieCollection()); }
public ActionResult Login(VmLogin login) { if (ModelState.IsValid) { User user1 = db.Users.FirstOrDefault(u => u.Username == login.Username); if (user1 != null) { if (Crypto.VerifyHashedPassword(user1.Password, login.Password)) { Session["Logginer"] = true; Session["LogginerId"] = user1.Id; return(RedirectToAction("BlogCreate", "Blog")); } else { ModelState.AddModelError("Password", "Incorrect Password!"); return(View(login)); } } else { ModelState.AddModelError("Username", "Incorrect Username!"); return(View(login)); } } return(View(login)); }
public ActionResult Login(VmLogin model, string returnUrl) { try { // Verification. if (ModelState.IsValid) { // Initialization. var loginInfo = Db.LoginByUsernamePassword(model.Username, model.Password).ToList(); // Verification. if (loginInfo.Count() > 0) { // Initialization. var logindetails = loginInfo.First(); // Login In. this.SignInUser(logindetails.UserName, false); // Info. return(this.RedirectToLocal(returnUrl)); } else { // Setting. ModelState.AddModelError(string.Empty, "Invalid username or password."); } } } catch (Exception ex) { // Info Console.Write(ex); } // If we got this far, something failed, redisplay form return(this.View(model)); }
public ActionResult registrarUsuario(VmLogin vmLogin) { try { Cliente cliente = new Cliente(); cliente.Usuario = vmLogin.usuario; cliente.Clave = vmLogin.clave; cliente.Correo = vmLogin.correo; cliente.IDApi = null; cliente.Foto = "/Content/images/user.png"; //string imageFile = System.Web.HttpContext.Current.Server.MapPath("~/Content/images/user.png"); //var srcImage = Image.FromFile(imageFile); //var stream = new MemoryStream(); //srcImage.Save(stream, ImageFormat.Png); //cliente.Foto= stream.ToArray(); cliente.Rol = "User"; GYMEntities context = new GYMEntities(); context.Cliente.Add(cliente); context.SaveChanges(); Session["objUsuario"] = cliente; Session["rol"] = "C"; return(RedirectToAction("gimnacioMapa")); } catch (Exception ex) { return(View(vmLogin)); } }
public async Task <KeyValuePair <bool, string> > GetToken(VmLogin para) { try { using (var client = CreateHttpClient(AppSetting.Instance.Server)) { var uri = CreateUri($"/api/Token/Login", AppSetting.Instance.Server); var jsonData = new StringContent(JsonConvert.SerializeObject(para), Encoding.UTF8, MediaType.JSON); var response = await client.PostAsync(uri, jsonData); var jsonString = await response.Content.ReadAsStringAsync(); var msg = JsonConvert.DeserializeObject <string>(jsonString); if (response.IsSuccessStatusCode) { return(new KeyValuePair <bool, string>(true, msg)); } else { return(new KeyValuePair <bool, string>(false, $"[{(int)response.StatusCode} {response.StatusCode}] {msg}")); } } } catch (Exception ex) { return(new KeyValuePair <bool, string>(false, ex.ToString())); } }
public async Task <string> LoginAsync(VmLogin para) { try { var proxyLogin = new ProxyLogin(); var tokenOffical = await proxyLogin.LoginAsync(para); if (tokenOffical == null || tokenOffical.Count <= 1) { return("登陆失败,请检查用户名或密码是否正确"); } BusinessCache.UserLogin.UserName = para.UserName; BusinessCache.UserLogin.Password = para.Password; BusinessCache.UserLogin.PasswordTran = para.PasswordTran; BusinessCache.UserLogin.TokenOffical = tokenOffical; await BusinessCache.UserAccounts.UpdateTokenOfficalAsync(para.UserName, tokenOffical); BusinessCache.UserProxies.UpdateFromUserAccount(BusinessCache.UserAccounts); return(string.Empty); } catch (Exception ex) { return(ex.ToString()); } }
public ActionResult Login(VmLogin login) { if (ModelState.IsValid) { Models.Admins admin = db.Admins.FirstOrDefault(a => a.Username == login.Username); if (admin != null) { if (Crypto.VerifyHashedPassword(admin.Password, login.Password) == true) { Session["Loginner"] = admin; Session["LoginnerId"] = admin.Id; return(RedirectToAction("Dashboard")); } else { ModelState.AddModelError("Password", "Wronge"); } } else { ModelState.AddModelError("Username", "Wronge"); } } return(View()); }
public User CheckLogin(VmLogin model) { var uid = model.Uid; var pwd = model.Pwd;//散列 //如果存在满足条件的记录,则返回第一条 //如果不存在,返回null // Lamda表达式 Linq for sql var item = _context.User.FirstOrDefault(m => m.UserName == uid && m.Password == pwd); return(item); }
private async void btnLogin_Click(object sender, EventArgs e) { Text = "登陆中,请稍后..."; this.UiFreeze(false); var repo = new LoginRepository(); var para = new VmLogin() { UserName = txtUserName.Text, Password = txtPassword.Text, PasswordTran = txtPasswordTran.Text }; var msg = await repo.LoginAsync(para); if (string.IsNullOrEmpty(msg)) { Text = "服务器验证..."; var retToken = await repo.GetTokenAsync(para); if (retToken.Key) { BusinessCache.UserLogin.TokenServer = retToken.Value; Text = "同步服务器数据(项目概要)..."; BusinessCache.ProjectOverviewList = await repo.SyncDataProjectOverviewAsync(BusinessCache.UserLogin); Text = "同步服务器数据(付息计划)..."; BusinessCache.ProjectPayments = await repo.SyncDataProductPaymentAsync(BusinessCache.UserLogin); Text = "初始化..."; var mainForm = new frmMain(); mainForm.OnWindowClosed -= MainForm_OnWindowClosed; mainForm.Show(); mainForm.OnWindowClosed += MainForm_OnWindowClosed; Hide(); } else { MessageBox.Show(retToken.Value, string.Empty, MessageBoxButtons.OK); } } else { Text = "登陆失败"; MessageBox.Show(msg, string.Empty, MessageBoxButtons.OK); } this.UiFreeze(true); }
public ActionResult loginFB(VmLogin vm) { try { Cliente cliente = _context.Cliente.FirstOrDefault(x => x.IDApi == vm.FbID); if (cliente == null) { cliente = new Cliente(); cliente.Usuario = vm.usuario; cliente.Clave = ""; if (vm.correo != null && vm.correo != "undefined") { cliente.Correo = vm.correo; } else { cliente.Correo = ""; } cliente.IDApi = vm.FbID; cliente.Foto = vm.FbID; //vm.imagen; //string imageFile = System.Web.Http_context.Current.Server.MapPath("~/Content/images/user.png"); //var srcImage = Image.FromFile(imageFile); //var stream = new MemoryStream(); //srcImage.Save(stream, ImageFormat.Png); //cliente.Foto= stream.ToArray(); //cliente.Rol = "User"; _context.Cliente.Add(cliente); _context.SaveChanges(); Session["objUsuario"] = cliente; Session["rol"] = "C"; return(RedirectToAction("verMapa")); } Session["objUsuario"] = cliente; Session["rol"] = "C"; return(RedirectToAction("verMapa")); } catch (Exception) { return(RedirectToAction("login")); } }
public ActionResult Login(VmLogin model) { if (!ModelState.IsValid) { return(View(model)); } //查数据库,用户是否正确 var userNow = _accountService.CheckLogin(model); if (userNow == null) { ModelState.AddModelError("", "用户名或密码错误"); return(PartialView(model)); } Session.Add("userNow", userNow); //授权 AspFormsAuthentication.SetAuthenticationToken(userNow.UserName, new[] { "Logon" }, true); return(RedirectToAction("Index", "Home")); }
public static async Task <UserProxy> LoginAsync(UserProxy proxy) { if (proxy != null) { var proxyLogin = new ProxyLogin(); var para = new VmLogin() { UserName = proxy.UserName, Password = proxy.Password, }; proxy.TokenOffical = await proxyLogin.LoginAsync(para); if (proxy.HasValue) { return(proxy); } } return(null); }
public ActionResult login(VmLogin vm) { try { Cliente cliente = _context.Cliente.FirstOrDefault(x => x.Usuario == vm.usuario && x.Clave == vm.clave); if (cliente != null) { if (cliente.IDApi != null) { return(RedirectToAction("login")); } Session["objUsuario"] = cliente; Session["rol"] = "C"; return(RedirectToAction("verMapa")); } Asociado asociado = _context.Asociado.FirstOrDefault(x => x.Usuario == vm.usuario && x.Clave == vm.clave); if (asociado != null) { Session["objUsuario"] = asociado; Session["rol"] = "A"; return(RedirectToAction("estadoCuenta")); } Administrador administrador = _context.Administrador.FirstOrDefault(x => x.Usuario == vm.usuario && x.Clave == vm.clave); if (administrador != null) { Session["objUsuario"] = administrador; Session["rol"] = "D"; return(RedirectToAction("listarAsociados")); } return(View(vm)); } catch (Exception) { return(View(vm)); } }
public static async Task <UserAccount> LoginAsync(UserAccount account) { var ret = new List <UserAccount>(); if (account != null) { var proxyLogin = new ProxyLogin(); var para = new VmLogin() { UserName = account.UserName, Password = account.Password, PasswordTran = account.PasswordTran, }; account.TokenOffical = await proxyLogin.LoginAsync(para); if (account.HasValue) { return(account); } } return(null); }
public ActionResult login(VmLogin vmLogin) { try { GYMEntities context = new GYMEntities(); Cliente cliente = context.Cliente.FirstOrDefault(x => x.Usuario == vmLogin.usuario && x.Clave == vmLogin.clave); if (cliente == null) { Asociado asociado = context.Asociado.FirstOrDefault(x => x.Usuario == vmLogin.usuario && x.Clave == vmLogin.clave); if (asociado == null) { Administrador administrador = context.Administrador.FirstOrDefault(x => x.Usuario == vmLogin.usuario && x.Clave == vmLogin.clave); if (administrador == null) { return(View(vmLogin)); } Session["objUsuario"] = administrador; Session["rol"] = "D"; return(RedirectToAction("dashboard")); } Session["objUsuario"] = asociado; Session["rol"] = "A"; return(RedirectToAction("estadoCuenta")); } Session["objUsuario"] = cliente; Session["rol"] = "C"; return(RedirectToAction("gimnacioMapa")); } catch (Exception) { return(View(vmLogin)); } }
public ActionResult Login(VmLogin login) { if (ModelState.IsValid) { User user = db.Users.FirstOrDefault(a => a.Username == login.Username); if (user != null) { if (Crypto.VerifyHashedPassword(user.Password, login.Password) == true) { Session["LoginnedUser"] = user; Session["LoginnedUserId"] = user.Id; return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("Password", "Incorrect Password!"); return(View(login)); } } else { ModelState.AddModelError("Username", "Incorrect Username!"); return(View(login)); } } #region Wish list HttpCookie cookie = Request.Cookies["WishList"]; if (cookie != null) { List <string> WishList = cookie.Value.Split(',').ToList(); WishList.RemoveAt(WishList.Count - 1); ViewBag.WishList = WishList; ViewBag.WishListCount = WishList.Count; } else { ViewBag.WishListCount = 0; } #endregion #region Cart list HttpCookie cookieCart = Request.Cookies["Cart"]; List <string> CartList = new List <string>(); if (cookieCart != null) { CartList = cookieCart.Value.Split(',').ToList(); CartList.RemoveAt(CartList.Count - 1); ViewBag.CartList = CartList; ViewBag.CartListCount = CartList.Count; } else { ViewBag.CartListCount = 0; } #endregion ViewBag.HomeSetting = db.HomeSettings .Include("HomeSocials") .Include("HomeSocials.SocialType").FirstOrDefault(); return(View(login)); }
public async Task <KeyValuePair <bool, string> > GetTokenAsync(VmLogin para) { var proxy = new ProxyServer(); return(await proxy.GetToken(para)); }