Bootstrap 4.3.1 dropdown login form redirect upon success - authentication

I am building a site where users can login via a Bootstrap Dropdown, i did have it working, it would log user in and refresh the whole page with login session BUT if user entered wrong creds it wouldn't stay open and alert them. I got around this by putting the login form in an iframe in the dropdown but it's no longer starting the session - any ideas please? I'm trying to not be vague so here is the code in the iframe and the actual URL below that - thank you :)
<div class="header_login_form_dropdown">Login</div>
<form name="login" action="" method="post" class="form">
<div class="form-group">
<label class="login_form_dropdown" for="lopc_username">Email</label>
<input type="email" class="form-control" id="lopc_username" placeholder="email#company.com" name="lopc_username">
</div>
<div class="form-group">
<label class="login_form_dropdown" for="lopc_password">Password</label>
<input type="password" class="form-control" id="lopc_password" name="lopc_password">
</div>
Forgot password
<button type="submit" name="submit" class="btn btn-primary login_btn">LOGIN</button>
<div style="padding:15px 0 15px 0; border-top: 2px solid #eee; font-size: 14px; color: #696969">
New customer? Register here
</div>
<?php
if (isset($_POST['submit']))
{
include('../265451/92631043.php');
$lopc_username = mysqli_real_escape_string($conn,$_POST['lopc_username']);
$lopc_password = mysqli_real_escape_string($conn,(md5($_POST['lopc_password'])));
$lopc_last_login = date("Y-m-d H:i:s");
$query = "SELECT * FROM lopc_reg_users WHERE lopc_username = '$lopc_username' AND lopc_password = '$lopc_password' ";
$result = mysqli_query($conn,$query);
if(mysqli_num_rows($result) == 1)
{
$_SESSION['lopc_username'] = $_POST['lopc_username'];
$lopc_username = $_SESSION['lopc_username'];
$query2 = "UPDATE lopc_reg_users SET lopc_last_login = '$lopc_last_login' WHERE lopc_username = '$lopc_username' ";
$result2 = mysqli_query($conn,$query2);
//header("Location: ".$_SERVER['PHP_SELF']);
?>
<script>
window.parent.location.reload();
</script>
<?php
exit;
}
else
{
echo '<div class="login_error">Username or password does not exist.</div>';
}
}
?>
</form>
https://littleorangeprinting.co.uk/2021
Login: test#test.com
Pass: testing4321

Related

How can I show error message in ASP.NET Core MVC?

I want to show an error message when login failed.
This is my html markup:
<form class="modal-content animate" action="/Login/SignInTeacher" method="post">
#Html.AntiForgeryToken()
<div class="imgcontainer">
<span onclick="document.getElementById('id02').style.display='none'" class="close" title="Close Modal">×</span>
<img src="~/images/Login4.png" alt="Avatar" class="img-fluid" style="height: 300px;">
</div>
<div class="container">
<input type="text" class="form-control" name="Email" placeholder="Email Adresiniz" aria-label="Username" aria-describedby="basic-addon1" style="font-size: medium;">
<br>
<input type="password" class="form-control" name="Parola" placeholder="Şifreniz" aria-label="Username" aria-describedby="basic-addon1" style="font-size: medium;">
<br>
<button type="submit" class="btn btn-block btn-outline-success btn-lg">Login</button>
<br>
<label style="font-size: medium; margin-left: 0%;">
<input type="checkbox" checked="checked" name="remember"> Remember me
</label>
</div>
<div class="container" style="background-color:#f1f1f1">
<button type="button" onclick="document.getElementById('id02').style.display='none'" class="btn btn-lg btn-danger">Cancel</button>
<span class="psw">Forgot password?</span>
</div>
</form>
This is my controller code
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> SignInTeacher(Teacher t)
{
SHA1 sha = new SHA1CryptoServiceProvider();
string willbeEncrypted = s.Parola;
string encrypted = Convert.ToBase64String(sha.ComputeHash(Encoding.UTF8.GetBytes(willbeEncrypted)));
var info = c.Teachers.FirstOrDefault(x => x.Email == s.Email && x.Parola == encrypted);
if (info != null)
{
var claims = new List<Claim>
{
new Claim(ClaimTypes.Name,s.Email)
};
var userIdentity = new ClaimsIdentity(claims, "Login");
ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(userIdentity);
await HttpContext.SignInAsync(claimsPrincipal);
var value = from deger in c.Teachers
where deger.Email == s.Email
select deger.Email;
var nameuser = value;
return RedirectToAction("Main", "Home", new { user = nameuser });
}
return RedirectToAction("Index", "Home");
}
When user logs in successfully, the main page opens; when login fails, the main page does not open return same page (refresh) but I can't show the error message instead of page refresh like this "Username or password is wrong".
I tried it with viewbag but that did not work because this command return RedirectToAction("Index", "Home"); prevent the viewbag message.
when login failed main page does not open return same page(refresh) but I cant achieve show the error message instead of page refresh like this "Username or password is wronng".
To achieve your requirement, you can try to pass error message through TempData, like below.
TempData["ErrorMes"] = "Username or password is wronng";
return RedirectToAction("Index", "Home");
Display error message in Index page
<span class="text-danger">#TempData["ErrorMes"]</span>
I recommend to use ModelState.AddModelError like below, it'll return to the same login view with model error and model state will be invalid
Example :
if(isLoginSuccess)
{
return RedirectToAction("Main", "Home");
}else
{
ModelState.AddModelError("InvalidLogin", "Invalid Login Attempt");
return View(loginViewModel);
}

Why do I keep seeing the undefined index error for line 13 ('file')?

I am trying to create a simple drag and drop page using php. When I click the "submit" button, I get an error: Notice: Undefined index: file in C:\xampp\htdocs\phpfiles\DragAndDrop\includes\gallery-upload.inc.php on line 13. Why is it not reading the "file" index from the htmlphp?
Here is the HTML and PHP code:
enter code here
<!--continuted from HTML page-->
</section>
<?php
$_SESSION['username'] = "Admin";
if (isset($_SESSION['username'])) {
echo '<div class="gallery-upload">
<form action="includes/gallery-upload.inc.php" method="post" enctype="mutipart/form-data">
<input type="text" name="filename" placeholder="File Name...">
<input type="text" name="filetitle" placeholder="Image Title...">
<input type="text" name="filedesc" placeholder="Image description...">
<input type="file" name="file">
<button type="submit" name="submit">Upload</button>
</form>
</div>';
}
?>
</main>
</body>
</html>
<!--and the php page-->
<?php
if (isset($_POST['submit'])) {//checks submit form and posts the info
$newFileName = $_POST['filename'];
if (empty($_POST['filename'])) { //if filename is emptly
$newFileName = "gallery"; //if filename is empty, generates name
} else {
$newFileName = strtolower(str_replace(" ", "-", $newFileName)); //if spaces are in the name, creates stringholder
}
$imageTitle = $_POST['filetitle'];
$imageDesc = $_POST['filedesc'];
$file = $_FILES['file'];
}
?>
You have a typo:
mutipart/form-data
Should be
multipart/form-data

What exact code is needed for Wordpress/Woocommerce login/sign up pages [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am creating a small e-commerce website using wordpress & woocommerce but I'm not really understanding the login/signup abilities for users. I just want users who visit the site to be able to click a link on the home page where they can sign up and login (with the option to reset their passwords) and in return those customer details are saved within the user data for the wordpress admin to be able to see. What is the coding for this? Because I can't seem to get into a lot of these plugins.
<?php
global $wpdb, $user_ID;
$firstname='';
$lastname='';
$username='';
$email='';
//if looged in rediret to home page
if ( is_user_logged_in() ) {
wp_redirect( get_option('home') );// redirect to home page
exit;
}
if(sanitize_text_field( $_POST['com_submit']) != ''){
$firstname=sanitize_text_field( $_REQUEST['com_firstname'] );
$lastname=sanitize_text_field( $_REQUEST['com_lastname']);
$username = sanitize_text_field( $_REQUEST['com_username'] );
$email = sanitize_text_field( $_REQUEST['com_email'] );
$password = $wpdb->escape( sanitize_text_field( $_REQUEST['com_password']));
$status = wp_create_user($username,$password,$email);
if (is_wp_error($status)) {
$error_msg = __('Username or Email already registered. Please try another one.','twentyten');
}
else{
$user_id=$status;
update_user_meta( $user_id,'first_name', $firstname);
update_user_meta( $user_id,'last_name', $lastname);
//code to auto login start
$alar_enable_auto_login= get_option('alar_enable_auto_login');
if($alar_enable_auto_login==''){
$alar_enable_auto_login= 'true';
}
if($alar_enable_auto_login == 'true'){
if(!is_user_logged_in()){
$secure_cookie = is_ssl();
$secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, array());
global $auth_secure_cookie;
$auth_secure_cookie = $secure_cookie;
wp_set_auth_cookie($user_id, true, $secure_cookie);
$user_info = get_userdata($user_id);
do_action('wp_login', $user_info->user_login, $user_info);
}
}
//code to auto login end
wp_redirect( get_option('home') );// redirect to home page
exit;
}
}
?>
<div class="alar-registration-form">
<div class="alar-registration-heading">
<?php _e("Registration Form",'');?>
</div>
<?php if($error_msg!='') { ?><div class="error"><?php echo $error_msg; ?></div><?php } ?>
<form name="form" id="registration" method="post">
<div class="ftxt">
<label><?php _e("First Name :",'');?></label>
<input id="com_firstname" name="com_firstname" type="text" class="input" required value=<?php echo $firstname; ?> >
</div>
<div class="ftxt">
<label><?php _e("Last name :",'');?></label>
<input id="com_lastname" name="com_lastname" type="text" class="input" required value=<?php echo $lastname; ?> >
</div>
<div class="ftxt">
<label><?php _e("Username :",'');?></label>
<input id="com_username" name="com_username" type="text" class="input" required value=<?php echo $username; ?> >
</div>
<div class="ftxt">
<label><?php _e("E-mail :",'');?> </label>
<input id="com_email" name="com_email" type="email" class="input" required value=<?php echo $email; ?> >
</div>
<div class="ftxt">
<label><?php _e("Password :",'');?></label>
<input id="password1" name="com_password" type="password" required class="input" />
</div>
<div class="ftxt">
<label><?php _e("Confirm Password : ",'');?></label>
<input id="password2" name="c_password" type="password" class="input" />
</div>
<div class="fbtn"><input type="submit" name='com_submit' class="button" value="Register"/> </div>
</form>
</div>
<?php
}
//add registration shortcoode
add_shortcode( 'registration-form', 'alar_registration_shortcode' );
// function to login Shortcode
function alar_login_shortcode( $atts ) {
//if looged in rediret to home page
if ( is_user_logged_in() ) {
wp_redirect( get_option('home') );// redirect to home page
exit;
}
global $wpdb;
if(sanitize_text_field( $_GET['login'] ) != ''){
$login_fail_msg=sanitize_text_field( $_GET['login'] );
}
?>
<div class="alar-login-form">
<?php if($login_fail_msg=='failed'){?>
<div class="error" align="center"><?php _e('Username or password is incorrect','');?></div>
<?php }?>
<div class="alar-login-heading">
<?php _e("Login Form",'');?>
</div>
<form method="post" action="<?php echo get_option('home');?>/wp-login.php" id="loginform" name="loginform" >
<div class="ftxt">
<label><?php _e('Login ID :','');?> </label>
<input type="text" tabindex="10" size="20" value="" class="input" id="user_login" required name="log" />
</div>
<div class="ftxt">
<label><?php _e('Password :','');?> </label>
<input type="password" tabindex="20" size="20" value="" class="input" id="user_pass" required name="pwd" />
</div>
<div class="fbtn">
<input type="submit" tabindex="100" value="Log In" class="button" id="wp-submit" name="wp-submit" />
<input type="hidden" value="<?php echo get_option('home');?>" name="redirect_to">
</div>
</form>
</div>
just copy and past This code where do you want to add register login form

Inserting into the db with PDO

<form action="uploads.php" method="post" enctype="multipart/form-data" id="upload" class="upload">
<fieldset>
<legend>Upload</legend><br/>
Title: <input type="text" name="name" id="name" class="name" required> <br/><br/>
<textarea name="description" rows="6" cols="35" maxlength="120"></textarea><br/>
<input type="file" id="file" name="file[]" required multiple> <br/>
<input type="submit" id="submit" name="submit" value="Upload">
</fieldset>
<div class="bar">
<span class="bar-fill" id="pb"><span class="bar-fill-text" id="pt"></span></span>
</div>
<div id="uploads" class="uploads">
Uploaded file links will appear here.
</div>
<?php
// configuration
$dbhost = "localhost";
$dbname = "blog";
$dbuser = "root";
$dbpass = "pass";
// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
// new data
$name = 'name';
$mime = 'mime';
$data = 'data';
$size = 'size';
$description = 'description';
$created = 'created';
$url = 'url';
// query
$sql = "INSERT INTO videos (name,mime,data,size,description,created,url) VALUES (:name,:mime,:data,:size,:description,:created,:url)";
$q = $conn->prepare($sql);
$q->execute(array(':name'=>$name,
':mime'=>$mime,
':data'=>$data,
':size'=>$size,
':description'=>$description,
':created'=>$created,
':url'=>$url));
?>
I'm not so good with PDO, I can get videos to upload to my db, but I can't take in a name or anything. It just shows: name, description, size is 0 and etc. I've watched a few tutorials, but none of them show how to add it by what the user names it or describes it as, only what they put into the values goes to the database. I've also searched around on here and many other websites, but no luck.

Placement of Login code to website using Facebook account

Hi I'm new to web development. I would like to code for Login to website using Facebook account which I know that I need to add this js to install the Facebook SDK:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'your-app-id',
xfbml : true,
version : 'v2.4'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
However, I'm unsure on where to put it. It was mentioned that I should insert it directly after the opening <body> tag on each page I want to load it. However, Both of my register and login.php were done in floating div. There's no <body> tag. Hence, I not sure where to add this code in too:
<?php
if(!isset($_SESSION))
{
session_start();
}
require_once('config.php');
require_once('facebook.php');
require_once('PHPMailer/PHPMailerAutoload.php');
$facebook = new Facebook($config);
$fbUser = $facebook->getUser();
$_SESSION[$PROJECT_NAME . '-allowUser'] = true;
$uri = explode('/', strtok($_SERVER["REQUEST_URI"],'?'));
if ($fbUser) {
$user_profile = $facebook->api('/me');
$fbEmail = $user_profile["email"];
$fbId = $user_profile["id"];
}
Below is my login.php.
login.php
<div id="loginScreen">
<div class="xclose">
<em>×</em>
</div>
<div id="loghead">Facebook Connect</div>
<div class="articlepreview">
<form name="loginForm" method="post" id="registrationForm"
action="processLogin">
<div class="signintitle">Sign in to your Account</div>
<div class="form-group">
<input class="emailaddr" type="email" name="emailaddr" required
id="emailaddr" placeholder="Email Address"> <br> <input
type="password" name="password" required class="password"
id="id_password" placeholder=Password
<?php
if (preg_match ( "/^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/", $password )) {
echo "Your passwords is strong.";
} else {
echo "Your password is weak.";
}
?>
required>
</div>
<br>
<center>
<input class="greybtn" type="submit" value="Sign in" name="signin">
</center>
<div class="forgotpw" style="text-align: center;">
<br> Forgot Password? <br>
Create an Account <br>
</div>
</form>
</div>