public IActionResult LogIn(Tuser tuser) { var IpAddress = HttpContext.Features.Get <IHttpConnectionFeature>()?.RemoteIpAddress.ToString(); var logInUser = this.tuserService.GetTuser(tuser.CusrName); //驗證密碼 加密後 是否與 資料庫加密 密碼 符合 if (!this.tuserService.ValidatePassword(logInUser, tuser.CusrPw)) { ViewBag.Mess = "帳號密碼錯誤"; this.webLoginService.CreateWebLogin(tuser.CusrPw, IpAddress); return(View()); } else { this.webLoginService.CreateWebLogin(logInUser, IpAddress); HttpContext.Session.SetObject("user", logInUser); //var userAccount = logInUser.CusrName; //var userName = logInUser.Cname; //HttpContext.Session.SetString("userName", logInUser.Cname); //HttpContext.Session.SetString("userAccount", logInUser.CusrName); return(RedirectToAction("Home", "Home")); } }
public ActionResult <Create> Insert([FromBody] Create param) { if (param == null) { param = new Create(); param._message = _localizer["No parameters."]; return(BadRequest(param)); } if (!TryValidateModel(param)) { param._message = _localizer["The input is incorrect."]; return(BadRequest(param)); } try { var storeModel = new Tuser(); ReflectionUtility.Model2Model(param, storeModel); storeModel.TuserId = (Guid.NewGuid()).ToString(); storeModel.Registed = DateTime.Now; storeModel.Updated = DateTime.Now; storeModel.Version = 1; //登録 _context.Tusers.Add(storeModel); _context.SaveChanges(); Console.WriteLine("OK"); return(Ok(param)); } catch (Exception ex) { param._message = _localizer["System error Please inform system personnel.({0})", ex.Message]; return(BadRequest(param)); } }
public async Task <ActionResult> DeleteConfirmed(int id) { Tuser tuser = await db.Tusers.FindAsync(id); db.Tusers.Remove(tuser); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
/// <summary> /// 修改密碼 /// </summary> /// <param name="tuser">使用者Object</param> /// <param name="pwd">欲修改密碼</param> public void UpdatePwd(Tuser tuser, string pwd) { var setPwd = this.passwordEncryptService.HashPassword(pwd.Trim().ToLower()); tuser.CusrPw = setPwd; tuser.Ichgpwd = (tuser.Ichgpwd == null) ? 1 : tuser.Ichgpwd + 1; this.tuserRepository.Update(tuser); }
public async Task <ActionResult> Edit([Bind(Include = "id,username,Firstname,Lastname")] Tuser tuser) { if (ModelState.IsValid) { db.Entry(tuser).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(tuser)); }
public async Task <ActionResult> Create([Bind(Include = "id,username,Firstname,Lastname")] Tuser tuser) { if (ModelState.IsValid) { db.Tusers.Add(tuser); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(tuser)); }
/// <summary> /// Insert WebLogIn登入訊息(成功) /// </summary> /// <param name="cusrName">欲帳號Tuser Object</param> /// <param name="cname">登入者姓名</param> /// public void CreateWebLogin(Tuser tuser, string IpAddress) { var webLogin = new WebLogin { Cdate = DateTime.Now, Cname = tuser.Cname, CusrName = tuser.CusrName, Issuccess = true, IpAddress = IpAddress }; this.webLoginRepository.Create(webLogin); }
// GET: Tusers/Delete/5 public async Task <ActionResult> Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Tuser tuser = await db.Tusers.FindAsync(id); if (tuser == null) { return(HttpNotFound()); } return(View(tuser)); }
public ActionResult Login(Tuser avm) { Tuser user = db.Tuser.Where(x => x.Tuser_email == avm.Tuser_email && x.Tuser_password == avm.Tuser_password).SingleOrDefault(); if (user != null) { Session["Tuser_id"] = user.Tuser_id.ToString(); List <Tproduct> products = new List <Tproduct>(); Session["products"] = products; return(RedirectToAction("index")); } else { ViewBag.error = "Invalid username or password"; } return(View()); }
private async Task LoadSharedKeyAndQrCodeUriAsync(Tuser 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); }
public ActionResult ProductDetails(int?id) { ProductDetails productDetails = new ProductDetails(); Tproduct product = db.Tproduct.Where(x => x.product_id == id).SingleOrDefault(); productDetails.product_id = product.product_id; productDetails.product_name = product.product_name; productDetails.product_image = product.product_image; productDetails.product_price = product.product_price; Tcategory category = db.Tcategory.Where(x => x.category_id == product.product_fk_category).SingleOrDefault(); productDetails.category_name = category.category_name; Tuser user = db.Tuser.Where(x => x.Tuser_id == product.product_fk_user).SingleOrDefault(); productDetails.Tuser_name = user.Tuser_name; productDetails.Tuser_image = user.Tuser_image; productDetails.Tuser_contact = user.Tuser_contact; productDetails.product_fk_user = user.Tuser_id; return(View(productDetails)); }
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 Tuser { UserName = Input.Email, Email = Input.Email }; var result = await _userManager.CreateAsync(user); if (result.Succeeded) { result = await _userManager.AddLoginAsync(user, info); if (result.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider); return(LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } LoginProvider = info.LoginProvider; ReturnUrl = returnUrl; return(Page()); }
public ActionResult SignUp(Tuser uvm, HttpPostedFileBase imgfile) { string path = uploadimgfile(imgfile); if (path.Equals("-1")) { ViewBag.error = "Image couldnt upload"; } else { Tuser user = new Tuser(); user.Tuser_name = uvm.Tuser_name; user.Tuser_email = uvm.Tuser_email; user.Tuser_password = uvm.Tuser_password; user.Tuser_image = path; user.Tuser_contact = uvm.Tuser_contact; db.Tuser.Add(user); db.SaveChanges(); return(RedirectToAction("Login")); } return(View()); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var user = new Tuser { 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); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { 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>."); 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()); }
/// <summary> ///Check 登入帳號密碼 /// </summary> /// <param name="logInUser">欲帳號Tuser Object</param> /// <param name="cusrPw">該帳號正確加密密碼</param> /// <returns>密碼是否吻合</returns> public bool ValidatePassword(Tuser logInUser, string cusrPw) { return((logInUser == null) ? false : this.passwordEncryptService.ValidatePassword(cusrPw, logInUser.CusrPw)); }
private async void Receive_Message() { bool flag = false; bool keep = false; int Len; byte[] Stream_data = new byte[1024]; string message = null; if (flag_ == true) { userlistUpdator_Click(this, new EventArgs()); } this.flag_ = false; try { await Task.Run(() => { while (true) { //flag = false; //keep = false; if (N_stream.CanRead) { Len = N_stream.Read(Stream_data, 0, Stream_data.Length); //비동기 코드 message = Encoding.Default.GetString(Stream_data, 0, Len); if (message.Equals(Packet.Shutdown)) { ChatBox.Invoke((MethodInvoker) delegate() { ChatBox.AppendText("서버와의 연결이 끊어졌습니다.\n"); }); N_stream.Close(); client.Close(); goto EXIT; } else if (message.StartsWith("[$") && message.EndsWith("$]")) { List <string> Date_and_Text = message.Split('$').ToList <string>(); Date_and_Text.RemoveAt(0); Date_and_Text.RemoveAt(Date_and_Text.Count - 1);//'[', ']'제거 if (MessageBox.Show("일정이 왔습니다.\n일정 : " + Date_and_Text[0] + "\n내용 : " + Date_and_Text[1], "공유알림", MessageBoxButtons.YesNo) == DialogResult.Yes) { int checkNum = shareControler.ReceiveShareSchedule(id, Date_and_Text); if (checkNum == 0) { MessageBox.Show("일정이 수정되었습니다."); } else { MessageBox.Show("일정이 삽입되었습니다."); } } else { continue; } } else if (message.Equals(Packet.Approve)) { ChatBox.Invoke((MethodInvoker) delegate() { ChatBox.AppendText("접속성공!\n"); }); } else if (message.StartsWith("$$!") && message.EndsWith("!$$")) { string[] RealMessage = message.Split('!'); string ExitName = (RealMessage[1].Split('[')[1]).Split(']')[0]; UserArray.Remove(ExitName); ChatBox.Invoke((MethodInvoker) delegate() { ChatBox.AppendText(RealMessage[1] + "\n"); }); } else if (message.StartsWith("<@") && message.EndsWith("@>"))//UserList업데이트 { string[] targetuser = message.Split('@'); string[] Realtargetuser = targetuser[1].Split(','); //채팅할 유저 List <string> box = new List <string>(); foreach (string Tuser in UserArray) //기존 가진 유저 { keep = false; for (int i = 0; i < Realtargetuser.Length; i++) { if (Tuser.Equals(Realtargetuser[i])) { keep = true; } } if (keep == false) { box.Add(Tuser); } } foreach (string element in box) { UserArray.Remove(element); } } else if (message.Length >= 1) //한 글자 이상이라면, { string fromID = (message.Split(':')[0]).Split(' ')[0]; //어떤 아이디로부터 온것인가? foreach (string target in UserArray) { if (target.Equals(fromID)) //내가 채팅하는 사람들의 아이디중 하나와 일치한다. { flag = true; break; } } if (flag) //일치하면 내 채팅창에 메세지를 출력하라. { ChatBox.Invoke((MethodInvoker) delegate() { ChatBox.AppendText(message + "\n"); }); } flag = false; } } } EXIT :; }); } catch (SocketException errcode) { MessageBox.Show(errcode.Message); } }