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

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

Related

SiteFinity- Included Captcha Form Widget does not contain alt tag

SiteFinity noob here.
I've edited the widget via File Manager: Resource Packages>Bootstrap>MVC>Views>Captcha.
the file there is "Write.default.cshtml". I changed the following line-
<img data-sf-role="captcha-image" src='#Url.WidgetContent("assets/dist/img/dummy.jpg")'/>
to
<img data-sf-role="captcha-image" alt="captcha Image src='#Url.WidgetContent("assets/dist/img/dummy.jpg")'/>
However, although saved, this doesn't show up in the widget code when I put it on my form. I used File Manager, as I dont have a connection via .net editor.
Am I in the wrong place? Do I need to somehow restart the application?
Here is complete code:
#model Telerik.Sitefinity.Frontend.Forms.Mvc.Models.Fields.Captcha.CaptchaViewModel
#using Telerik.Sitefinity.Frontend.Mvc.Helpers;
#using Telerik.Sitefinity.Modules.Pages;
#using Telerik.Sitefinity.Services;
#Html.Script(ScriptRef.JQuery, "top", false)
<div data-sf-role="field-captcha-container" style="display:none;" class="#Model.CssClass form-group">
<div>
**<img data-sf-role="captcha-image" src='#Url.WidgetContent("assets/dist/img/dummy.jpg")'/>**
</div>
<a data-sf-role="captcha-refresh-button">#Html.Resource("NewCode")</a>
<div class="form-inline">
<div class="form-group">
<input data-sf-role="violation-messages" type="hidden" value='{"required": "#Model.ValidatorDefinition.RequiredViolationMessage"}' />
<label for='#Html.UniqueId("Textbox")'>#Html.Resource("TypeCodeAbove") </label>
<input id='#Html.UniqueId("Textbox")' type="text" data-sf-role="captcha-input" name="#Model.CaptchaAnswerFormKey" required="required" class="form-control input-sm"/>
</div>
</div>
<input type="hidden" data-sf-role="captcha-ca" name="#Model.CaptchaCorrectAnswerFormKey" />
<input type="hidden" data-sf-role="captcha-iv" name="#Model.CaptchaInitializationVectorFormKey" />
<input type="hidden" data-sf-role="captcha-k" name="#Model.CaptchaKeyFormKey" />
<input type="hidden" data-sf-role="captcha-settings" value="#Model.GenerateUrl"
</div>
#if (SystemManager.IsDesignMode)
{
var scriptUrl = Url.WidgetContent("Mvc/Scripts/Captcha/captcha.js");
var queryAddition = scriptUrl.Contains("?") ? "&" : "?";
var fullScriptUrl = scriptUrl + queryAddition + string.Format("_={0}", DateTime.UtcNow.Ticks.ToString());
<script type="text/javascript" src='#fullScriptUrl'></script>
}
else
{
#Html.Script(Url.WidgetContent("Mvc/Scripts/Captcha/captcha.js"), "bottom", false)
}
You'll need to make sure you are using the Bootstrap package. Go to Design > Page Template and see which resource package your page templates are using. Often times it's not the Bootstrap, but a copy of it.
A restart may help as well.

Bootstrap 4.3.1 dropdown login form redirect upon success

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

Insert ForEach Value in View into the Database MVC

Hi currently I am doing a shopping cart for my project
I would like to ask how can I import the values in a ForEach to the database.
For example, I have the following data in my view.
#foreach (Cart_Has_Services c in Model)
{
<div class="cart-row">
<div class="cart-items">#c.Cart_Service</div>
<div class="cart-items">#c.Additional_Notes</div>
<div class="cart-items">#c.Unit_Price</div>
<div class="cart-items">
<form asp-controller="Cart" asp-action="UpdateCart" formaction="post">
<input type="number" class="item-quantity-input" value="#c.Quantity" />
<input type="submit" class="btn btn-secondary" value="Update" />
</form>
</div>
<div class="cart-items">
<a asp-controller="Cart"
asp-action="DeleteItem"
asp-route-id="#c.Cart_Id"
onclick="return confirm('Delete Serivce #c.Cart_Service')">
Delete
</a>
</div>
</div>
}
As for now, I want to INSERT data (Cart Service, Additional Notes and Quantity) into my database (Order).
In my controller:
public IActionResult Checkout(Cart_Has_Services cart)
{
List<Cart_Has_Services> carts = DBUtl.GetList<Cart_Has_Services>("SELECT * FROM Cart");
string sql = #"INSERT INTO [Order](Order_Name,Order_Description,Order_Quantity)
VALUES('{0}','{1}',{2})";
int ord = DBUtl.ExecSQL(sql, cart.Cart_Service, cart.Additional_Notes, cart.Quantity);
if (ord == 1)
{
TempData["Message"] = "Perofrmance Successfully Created";
TempData["MsgType"] = "success";
return RedirectToAction("Success");
}
else
{
ViewData["Message"] = DBUtl.DB_Message;
ViewData["MsgType"] = "danger";
return View("ShoppingCart");
}
}
I tried the method that I have inserted but it created without inserting the data.
How can I solve this problem?
Hope can get some guidance.
Thank you
The form in the view only submit Quantity, without Cart_Service and Additional_Notes.
To submit their value, you may set hidden inputs in the form. Also you should set name attribute for the input for model binding.
#foreach (Cart_Has_Services c in Model)
{
<div class="cart-row">
<div class="cart-items">#c.Cart_Service</div>
<div class="cart-items">#c.Additional_Notes</div>
<div class="cart-items">#c.Unit_Price</div>
<div class="cart-items">
<form asp-controller="Cart" asp-action="UpdateCart" formaction="post">
<input type="hidden" name="Cart_Service" value="#c.Cart_Service" />
<input type="hidden" name="Additional_Notes" value="#c.Additional_Notes" />
<input type="number" name="Quantity" class="item-quantity-input" value="#c.Quantity" />
<input type="submit" class="btn btn-secondary" value="Update" />
</form>
</div>
<div class="cart-items">
<a asp-controller="Cart"
asp-action="DeleteItem"
asp-route-id="#c.Cart_Id"
onclick="return confirm('Delete Serivce #c.Cart_Service')">
Delete
</a>
</div>
</div>
}

Angular2: How to enable save button if any model value changed on edit page

I am new for angular 2. I have a page where we can edit details of customer profile. How to enable save button if any property of has been changed. I know it is possible in angular1 by using $watch.
It is simple. dirty check your form if you are using #angular/forms.
create form
export class HeroDetailComponent4 {
heroForm: FormGroup;
states = states;
constructor(private fb: FormBuilder) {
this.createForm();
}
createForm() {
this.heroForm = this.fb.group({
name: ['', Validators.required ],
street: '',
city: '',
state: '',
zip: '',
power: '',
sidekick: ''
});
}
}
HTML:
<h2>Hero Detail</h2>
<h3><i>A FormGroup with multiple FormControls</i></h3>
<form [formGroup]="heroForm" novalidate>
<button (click)="submit()" [disabled]="!heroForm.dirty" type="button">Submit</button>
<div class="form-group">
<label class="center-block">Name:
<input class="form-control" formControlName="name">
</label>
</div>
<div class="form-group">
<label class="center-block">Street:
<input class="form-control" formControlName="street">
</label>
</div>
<div class="form-group">
<label class="center-block">City:
<input class="form-control" formControlName="city">
</label>
</div>
<div class="form-group">
<label class="center-block">State:
<select class="form-control" formControlName="state">
<option *ngFor="let state of states" [value]="state">{{state}}</option>
</select>
</label>
</div>
<div class="form-group">
<label class="center-block">Zip Code:
<input class="form-control" formControlName="zip">
</label>
</div>
<div class="form-group radio">
<h4>Super power:</h4>
<label class="center-block"><input type="radio" formControlName="power" value="flight">Flight</label>
<label class="center-block"><input type="radio" formControlName="power" value="x-ray vision">X-ray vision</label>
<label class="center-block"><input type="radio" formControlName="power" value="strength">Strength</label>
</div>
<div class="checkbox">
<label class="center-block">
<input type="checkbox" formControlName="sidekick">I have a sidekick.
</label>
</div>
</form>
use heroForm.dirty to check whether form data is changed. it will set to true if any control inside heroForm has been changed.
<button (click)="submit()" [disabled]="!heroForm.dirty" type="button">Submit</button>
Refer angular docs for more info
you can use form control validation for it.
some thing like this in html template:
<form fxLayout="column" [formGroup]="form">
<mat-form-field class="mb-1">
<input matInput [(ngModel)]="userProfileChangeModel.firstName" placeholder="نام"
[formControl]="form1.controls['fname']">
<small *ngIf="form1.controls['fname'].hasError('required') && form1.controls['fname'].touched"
class="mat-text-warn">لطفا نام را وارد نمایید.
</small>
<small *ngIf="form1.controls['fname'].hasError('minlength') && form1.controls['fname'].touched"
class="mat-text-warn">نام باید حداقل 2 کاراکتر باشد.
</small>
<small *ngIf="form1.controls['fname'].hasError('pattern') && form1.controls['fname'].touched"
class="mat-text-warn">لطفا از حروف فارسی استفاده نمائید.
</small>
</mat-form-field>
<mat-card-actions>
<button mat-raised-button (click)="editUser()" color="primary" [disabled]="!form1.valid" type="submit">
ذخیره
</button>
</mat-card-actions>
</form>
and like this in ts file:
this.form = this.bf.group({
fname: [null, Validators.compose([
Validators.required,
Validators.minLength(2),
Validators.maxLength(20),
Validators.pattern('^[\u0600-\u06FF, \u0590-\u05FF]*$')])],
});
if:
[disabled]="!form1.valid"
is valid save button will be active
bast regards.
You can use disabled option like below :
<button [disabled]="isInvalid()" type="button" (click) = "searchClick()" class="button is-info">
<span class="icon is-small">
<i class="fa fa-search" aria-hidden="true"></i>
</span>
<span>Search</span>
</button>
you can create isInvalid() in your ts file and check if that property is empty or not and return that boolean value
and for hide button on a state you can use *ngIf in line directive.
This worked for me, pls try.
In your html,
<input type="text" [ngModel]="name" (ngModelChange)="changeVal()" >
<input type="text" [ngModel]="address" (ngModelChange)="changeVal()" >
<input type="text" [ngModel]="postcode" (ngModelChange)="changeVal()" >
<button [disabled]="noChangeYet" (click)="clicked()" >
<span>SUBMIT</span>
</button>
In your component
export class customer implements OnInit {
name: string;
address: string;
postcode: string;
noChangeYet:boolean = true;
constructor() {}
changeVal(){ // triggers on change of any field(s)
this.noChangeYet = false;
}
clicked(){
// your function data after click (if any)
}
}
Hope this is what you need.
Finally I resolved this issue.
import { Component, Input, Output, OnInit, AfterViewInit, EventEmitter, ViewChild } from '#angular/core';
#Component({
selector: 'subscribe-modification',
templateUrl: './subscribe.component.html'
})
export class SampleModifyComponent implements OnInit, AfterViewInit {
disableSaveSampleButton: boolean = true;
#ViewChild('sampleModifyForm') sampleForm;
ngAfterViewInit() {
setTimeout(() => {
this.sampleForm.control.valueChanges.subscribe(values => this.enableSaveSampleButton());
}, 1000);
}
enableSaveSampleButton() {
console.log('change');
this.disableSaveSampleButton = false;
}
}
HTML
<button id="btnSave" class="btn btn-primary" (click)="save()" />

[Symfony]--sfGuardPlugin--SignIn

I use symfony 1.4
In my index page, I have created some fields as login form.
When using sfGuardPlugin, it generate automaticly its form.
So, what I'm searching for is how to replace the default form created by the new which I have created.
thanks
By default, sfGuardAuth module comes with 2 very simple templates:
signinSuccess.php
secureSuccess.php
If you want to customize one of these templates:
Create a sfGuardAuth module in your application (don't use the
init-module task, just create a sfGuardAuth directory)
Create a template with the name of the template you want to customize in
the sfGuardAuth/templates directory
symfony now renders your template instead of the default one
More info: https://github.com/Garfield-fr/sfDoctrineGuardPlugin
Edit:
You must set up the settings.yml
enabled_modules: [default, sfGuardAuth, sfGuardUser]
.actions:
login_module: sfGuardAuth
login_action: signin
This is my signinSuccess.php
<h2>Bejelentkezés</h2>
<form id="loginform" action="<?php echo url_for('#sf_guard_signin') ?>" method="post">
<input type="hidden" name="signin[_csrf_token]" value="2a831d070cdd61d81bb1572be3f52d21" id="signin__csrf_token" /> <p>
<label class="required" for="username">Felhasználónév vagy Email:</label><br/>
<input type="text" name="signin[username]" id="signin_username" class="text" /> </p>
<p>
<label class="required" for="password">Jelszó:</label><br/>
<input type="password" name="signin[password]" id="signin_password" class="text" /> </p>
<p>
<input type="submit" class="btn btn-green big" value="Signin" />
</p>
<div class="clear"> </div>
<?php echo $form->renderHiddenFields(); ?>
</form>