public async Task <IActionResult> PutCustomerReg(int id, CustomerReg customerReg) { if (id != customerReg.Id) { return(BadRequest()); } _context.Entry(customerReg).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerRegExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult ResetPassword(CustomerReg customer) { var user = _context.CustomerReg.Where(x => x.EmailId == customer.EmailId && x.TokenId == customer.TokenId).FirstOrDefault(); if (user != null) { CustomerReg model = _context.CustomerReg.FirstOrDefault(x => x.EmailId == customer.EmailId); DateTime date = (DateTime)model.Date; TimeSpan duration = new TimeSpan(0, 0, 5, 0); DateTime value = date.Add(duration); if (DateTime.Now <= value) { model.Password = CommonMethods.ConverttoEncrypt(customer.Password); model.ConfirmPassword = CommonMethods.ConverttoEncrypt(customer.Password); _context.Entry(model).State = EntityState.Modified; _context.SaveChanges(); return(Ok(new { success = true, status = 200, data = "Password has been changed. Kindly login with new password" })); } else { return(Ok(new { success = false, status = 400, data = "Token has been expired. Please try again." })); } } else { return(Ok(new { success = false, status = 400, data = "Token or EmailId is invalid. Please try again." })); } }
public IActionResult ActivateAccount(CustomerReg customer) { var user = _context.CustomerReg.Where(x => x.EmailId == customer.EmailId && x.TokenId == customer.TokenId).FirstOrDefault(); if (user != null) { CustomerReg model = _context.CustomerReg.FirstOrDefault(x => x.EmailId == customer.EmailId); model.Count = 0; model.Status = true; model.Date = null; model.TokenId = null; _context.Entry(model).State = EntityState.Modified; _context.SaveChanges(); return(Ok(new { success = true, status = 200, data = "Account has been activated." })); } else { return(Ok( new { status = false, code = 401, message = "Invalid details" })); } }
public IActionResult ForgotPassword(CustomerReg customer) { var user = _context.CustomerReg.Where(x => x.EmailId == customer.EmailId).FirstOrDefault(); if (user != null) { CustomerReg model = _context.CustomerReg.FirstOrDefault(x => x.EmailId == customer.EmailId); model.Date = DateTime.Now; _context.Entry(model).State = EntityState.Modified; _context.SaveChanges(); var signinKey = new SymmetricSecurityKey( Encoding.UTF8.GetBytes(_config["Jwt:SigningKey"])); int expiryInMinutes = Convert.ToInt32(_config["Jwt:ExpiryInMinutes"]); var token = new JwtSecurityToken( issuer: _config["Jwt:Site"], audience: _config["Jwt:Site"], expires: DateTime.UtcNow.AddMinutes(expiryInMinutes), signingCredentials: new SigningCredentials(signinKey, SecurityAlgorithms.HmacSha256) ); string tokenData = new JwtSecurityTokenHandler().WriteToken(token); DateTime expiration = token.ValidTo; //var verifyUrl2 = "/Login/ResetPassword/"; //var link2 = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, verifyUrl2); var link = "http://*****:*****@gmail.com", "Messsage"); var toEmail = new MailAddress("*****@*****.**"); var fromEmailPassword = "******"; string subject = "Reset Password"; string body = "Hi,<br/><br/>We got request for reset your account password. Please find the token and click on the below link to reset your password" + "<br/><br/><a href=" + link + ">Reset Password link</a> " + "<br/><br/>Token=" + tokenData; model.TokenId = tokenData; _context.Entry(model).State = EntityState.Modified; _context.SaveChanges(); var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromEmail.Address, fromEmailPassword), }; using (var message = new MailMessage(fromEmail, toEmail) { Subject = subject, Body = body, IsBodyHtml = true }) smtp.Send(message); return(Ok(new { success = true, status = 200, data = "Kindly check your Email Id to rest password." })); } return(Ok(new { success = false, status = 400, data = "Unauthorizes user" })); }
public IActionResult AccountVerify(CustomerReg customer) { var user = _context.CustomerReg.Where(x => x.EmailId == customer.EmailId).FirstOrDefault(); if (user != null) { CustomerReg model = _context.CustomerReg.FirstOrDefault(x => x.EmailId == customer.EmailId); var link = "http://*****:*****@gmail.com", "Task For the verification"); var toEmail = new MailAddress("*****@*****.**"); var fromEmailPassword = "******"; string subject = "Activate account"; string body = "Hi,<br/><br/> Kindly click on below link to activate your Account" + "<br/><br/><a href=" + link + ">Activate your account</a>" + "<br/><br/>Token=" + tokenData; model.TokenId = tokenData; _context.Entry(model).State = EntityState.Modified; _context.SaveChanges(); var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromEmail.Address, fromEmailPassword), }; using (var message = new MailMessage(fromEmail, toEmail) { Subject = subject, Body = body, IsBodyHtml = true }) smtp.Send(message); return(Ok(new { success = true, status = 200, data = "Kindly check your Email Id to activate account." })); } else { return(Ok(new { success = false, status = 401, data = "Unauthorized user" })); } }
public IActionResult LogOut(CustomerReg c) { var user = _context.CustomerReg.Where(x => x.EmailId == c.EmailId).FirstOrDefault(); if (user != null) { CustomerReg model = _context.CustomerReg.FirstOrDefault(x => x.EmailId == c.EmailId); model.TokenId = null; model.Date = null; _context.Entry(model).State = EntityState.Modified; _context.SaveChanges(); return(Ok(new { success = true, status = 200, data = "Suucessfullly logged out" })); } else { return(Ok(new { success = false, status = 400, data = "Unauthorizes user" })); } }
public async Task <ActionResult <CustomerReg> > PostCustomerRegistration(CustomerReg cd) { //_context.CustomerRegistration.Add(CustomerRegistration); //await _context.SaveChangesAsync(); //return CreatedAtAction("GetCustomerRegistration", new { id = customerRegistration.Id }, customerRegistration); try { CustomerReg c = new CustomerReg(); c.FirstName = cd.FirstName; c.LastName = cd.LastName; c.EmailId = cd.EmailId; c.Password = CommonMethods.ConverttoEncrypt(cd.Password); c.ConfirmPassword = CommonMethods.ConverttoEncrypt(cd.ConfirmPassword); c.TokenId = cd.TokenId; c.MobileNo = cd.MobileNo; c.Date = cd.Date; c.Status = true; c.Count = 0; c.UserName = cd.UserName; //var user = _context.CustomerRegistration.Where(x => x.FirstName == cd.FirstName && x => x.FirstName == cd.LastName && x => x.EmailId == cd.EmailId && x.Password == CommonMethods.ConverttoEncrypt(cd.Password)); _context.CustomerReg.Add(c); _context.SaveChanges(); return(Ok( new { success = true, status = 200, data = "Registration successfully Completed please Login in to the Application" }));; } catch (Exception ex) { if (CustomerRegExists(cd.Id)) { return(Conflict()); } else { return(Ok(new { success = false, status = 401, data = "Invalid Credentials" })); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (chkBoxAgree.Checked && txtName.Text != "" && txtEmail.Text != "" && txtMobile.Text != "" && txtPassword.Text != "" && txtDOB.Text != "" && txtConfirmPass.Text != "") { try { CustomerReg reg = new CustomerReg(); reg.Name = txtName.Text; reg.Gender = ddlGender.SelectedValue; reg.Email = txtEmail.Text; reg.DOB = txtDOB.Text; reg.MobileNo = txtMobile.Text; reg.Address = txtAddress.Text; reg.Password = txtPassword.Text; bool status = reg.Save(); if (status == true) { ShowAlert("You Have Successfully Registered"); //Mail Send sendMailToClient(); sendEmailToAuthority(); ClearData(); } else { ShowAlert("Failed To Register"); } } catch (Exception ex) { ShowAlert(ex.Message.ToString()); } } else { //lblMessage.Text = "Please Provide All Data"; } }
private void btn_Create_Click(object sender, RoutedEventArgs e) { Button bt = sender as Button; if (bt.Content.ToString() == "Create") { BankDetails bnktail = new BankDetails(); bnktail.AccountBalance = int.Parse(accountBalanceTextBox.Text); bnktail.AccountName = accountNameTextBox.Text; bnktail.AccountNo = double.Parse(accountNoTextBox.Text); bnktail.AccountType = accountTypeComboBox.SelectionBoxItem.ToString(); bnktail.CustomerRegId = customerRegIdTextBox.Text; CustomerReg reg = new CustomerReg(); reg.AccountBalance = int.Parse(accountBalanceTextBox.Text); reg.AccountName = accountNameTextBox.Text; reg.AccountNo = double.Parse(accountNoTextBox.Text); reg.AccountType = accountTypeComboBox.SelectionBoxItem.ToString(); reg.Address = addressTextBox.Text; reg.Age = int.Parse(ageTextBox.Text); reg.Country = countryTextBox.Text; reg.CustomerRegId = customerRegIdTextBox.Text; reg.DOB = DateTime.Parse(dOBDatePicker.SelectedDate.Value.ToShortTimeString()); reg.FirstName = firstNameTextBox.Text; reg.LastName = lastNameTextBox.Text; reg.NextKin = nextKinTextBox.Text; reg.PhoneNo = double.Parse(phoneNoTextBox.Text); if (MessageBox.Show("Sure you want to Create", "Information", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { db.bnkdetails.Add(bnktail); db.custreg.Add(reg); db.SaveChanges(); MessageBox.Show("Account Created"); refresh(); } } if (bt.Content.ToString() == "Update") { var bnkdtl = double.Parse(accountNoTextBox.Text); var UpdateDtail = (from s in db.bnkdetails where s.AccountNo == bnkdtl select s).SingleOrDefault(); if (UpdateDtail != null) { UpdateDtail.AccountBalance = int.Parse(accountBalanceTextBox.Text); UpdateDtail.AccountName = accountNameTextBox.Text; UpdateDtail.AccountNo = double.Parse(accountNoTextBox.Text); UpdateDtail.AccountType = accountTypeComboBox.SelectionBoxItem.ToString(); UpdateDtail.CustomerRegId = customerRegIdTextBox.Text; db.SaveChanges(); } var account = double.Parse(accountNoTextBox.Text); var Update = (from s in db.custreg where s.AccountNo == account select s).SingleOrDefault(); Update.AccountBalance = double.Parse(accountBalanceTextBox.Text); Update.AccountName = accountNameTextBox.Text; Update.AccountNo = double.Parse(accountNoTextBox.Text); Update.AccountType = accountTypeComboBox.Text; Update.Address = addressTextBox.Text; Update.Age = int.Parse(ageTextBox.Text); Update.Country = countryTextBox.Text; Update.CustomerRegId = customerRegIdTextBox.Text; Update.DOB = DateTime.Parse(dOBDatePicker.SelectedDate.ToString()); Update.FirstName = firstNameTextBox.Text; Update.LastName = lastNameTextBox.Text; Update.NextKin = nextKinTextBox.Text; Update.PhoneNo = double.Parse(phoneNoTextBox.Text); if (MessageBox.Show("Sure you want to Update", "Information", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { db.SaveChanges(); MessageBox.Show("Account Updated"); } } if (bt.Content.ToString() == "Delete") { var account = double.Parse(accountNoTextBox.Text); var Delet = (from s in db.custreg where s.AccountNo == account select s).SingleOrDefault(); if (MessageBox.Show("Sure you want to Delete", "Information", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { db.custreg.Remove(Delet); db.SaveChanges(); MessageBox.Show("Account Deleted"); refresh(); } } }
public IActionResult Login(CustomerReg customer) { try { var value = _context.CustomerReg.Where(x => x.EmailId == customer.EmailId).FirstOrDefault(); if (value != null) { CustomerReg model = _context.CustomerReg.FirstOrDefault(x => x.EmailId == customer.EmailId); var password = CommonMethods.ConvertToDecrypt(model.Password); var data = _context.CustomerReg.Where(x => x.EmailId == customer.EmailId && password == customer.Password).FirstOrDefault(); if (data != null) { var accountStatus = _context.CustomerReg.Where(x => x.EmailId == customer.EmailId && x.Count >= 3).FirstOrDefault(); if (accountStatus == null) { var signinKey = new SymmetricSecurityKey( Encoding.UTF8.GetBytes(_config["Jwt:SigningKey"])); int expiryInMinutes = Convert.ToInt32(_config["Jwt:ExpiryInMinutes"]); var token = new JwtSecurityToken( issuer: _config["Jwt:Site"], audience: _config["Jwt:Site"], expires: DateTime.UtcNow.AddMinutes(expiryInMinutes), signingCredentials: new SigningCredentials(signinKey, SecurityAlgorithms.HmacSha256) ); var tokenData = new JwtSecurityTokenHandler().WriteToken(token); model.TokenId = tokenData; model.Date = DateTime.Now; _context.Entry(model).State = EntityState.Modified; _context.SaveChanges(); return(Ok( new { token = new JwtSecurityTokenHandler().WriteToken(token), expiration = token.ValidTo, EmailIds = model.EmailId, status = 200 })); } else { model.Status = false; _context.Entry(model).State = EntityState.Modified; _context.SaveChanges(); return(Ok( new { status = false, code = 401, message = "Account has been locked" })); } } else { model.Count = model.Count + 1; _context.Entry(model).State = EntityState.Modified; _context.SaveChanges(); var accountStatus = _context.CustomerReg.Where(x => x.EmailId == customer.EmailId && x.Count >= 3).FirstOrDefault(); if (accountStatus == null) { return(Ok( new { status = false, code = 401, message = "Invalid credentials" })); } else { model.Status = false; _context.Entry(model).State = EntityState.Modified; _context.SaveChanges(); return(Ok( new { status = false, code = 401, message = "Account has been locked" })); } } } else { CustomerReg models = _context.CustomerReg.FirstOrDefault(x => x.EmailId == customer.EmailId); models.Count = models.Count + 1; _context.Entry(models).State = EntityState.Modified; _context.SaveChanges(); return(Ok( new { status = false, code = 401, message = "Invalid credentials" })); } } catch (Exception ex) { return(Ok(new { status = ex })); } }