フォームから入力を受け取り、データベースからデータを検証し、正しい場合は right.html を返し、そうでない場合は wrong.html を返すログインおよび認証機能があります。パスワードは galaxy_user データベースに保存されます。uname の出力は次のとおりです。
u'sachitad'
passw の出力は次のとおりです。
u'f8566297ee28e8a3096497070b37b91d24c24243'
def login(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
u = ''.join(username)
p = hashlib.sha1(password).hexdigest()
a = GalaxyUser.objects.values_list('username', 'password')
uname = a[0][0]
passw = a[0][1]
user = authenticate(uname=u, passw=p)
if user is not None:
return render_to_response('right.html', context_instance=RequestContext(request))
else:
return render_to_response('wrong.html', context_instance=RequestContext(request))
else:
return render_to_response('login.html', context_instance=RequestContext(request))
編集: GalaxyUser テーブル:
id | create_time | update_time | email | password | external | deleted | purged | username | form_values_id | disk_usage |
+----+---------------------+---------------------+-------------------------------+------------------------------------------+----------+---------+--------+----------+----------------+------------+
| 1 | 2013-01-11 15:00:30 | 2013-01-11 15:00:30 | user1@gmail.com | f8566297ee28e8a3096497070b37b91d24c24243 | 0 | 0 | 0 | sachitad | NULL | NULL |
| 2 | 2013-01-11 15:01:01 | 2013-01-11 15:01:01 | user2@zurelsoft.com | f8566297ee28e8a3096497070b37b91d24c24243 | 0 | 0 | 0 | saugat | NULL | NULL |
+----+---------------------+---------------------+-------------------------------+------------------------------------------+----------+---------+--------+-
メールとパスワードで認証したい。